Description
Hello,
I found some example usage codes on the Internet, but I couldn't get the MCP4725 to work, I tested it with Arduino Nano and it worked.
Test code for Arduino Nano:
while (1) {
Wire.beginTransmission(0x62);
Wire.write(0x0F);
Wire.write(0xFF);
Wire.write(0x0);
Wire.write(0x0);
Wire.endTransmission();
}
Unfortunately I still couldn't get the I2C port to work correctly, there are some posts that say they had problems with I2C on these STM8S, and in my case the I2C_GetFlagStatus() function seems to be unable to read the register and so the routine freezes. The problem seems to be the lack of interrupt, because the initialization of the I2C module does not trigger interrupt events, so asking the code to wait for an interrupt, the code is stuck forever. Basically I found two initializations, one that activates the interrupt and one that does not activate.
This other file shows the activation of the interrupt on line 88, I've tried working with the interrupt, but it's a bit complex, and I believe you need to faithfully follow the steps outlined in ST's RM0016 document:
// ------------------------ Interrupts are enabled ------------------------
I2C1_ITR_ITEVTEN = 1; //Event Enables : SB, ADDR, ADD10, STOPF, BTF, WUFH
I2C1_ITR_ITBUFEN = 1; //Buffer Enables (if ITEVTEN) : RXNE, TXE
I2C1_ITR_ITERREN = 1; //Error Enables : BERR, ARLO, AF, OVR
It would be interesting to have an example of functional usage for I2C in the folder:
https://github.com/tenbaht/sduino/tree/development/test
Or:
https://github.com/tenbaht/sduino/tree/development/examples
P.S.: Ref.:
https://www.st.com/en/embedded-software/stsw-stm8004.html
https://www.st.com/resource/en/application_note/an3281-stm8-8bit-mcus-ic-optimized-examples-stmicroelectronics.pdf