Hello,
My MCP4725 froze more than once (eventually) when trying out different settings in the I2C routines.
Be aware that it may be necessary to use a MOSFET or relay to reset the MCP4725 programmatically or manually switch the power supply in the event of a communication failure.
I was having problems in the I2C writing routine, the data times were not correctly controlled.
Routines that worked for writing I2C using STM8S are here:
opened 07:47PM - 18 Jul 22 UTC
Hello,
I found some example usage codes on the Internet, but I couldn't get t… he MCP4725 to work, I tested it with Arduino Nano and it worked.
Test code for Arduino Nano:
```C++
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:
```C++
// ------------------------ 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
```
https://github.com/HomeSmartMesh/STM8_IoT_HelloWorld/blob/master/18_STM8L_HelloI2C/i2c.c
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
system
Closed
January 14, 2023, 10:52pm
2
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.