STM32 code needed to send simple data message via I2C
Budget: €8 – €30 EUR
I have an STM32G030F6P6 TSOP20 microcontroller that shall send an I2C message containing a value, stored in in a locally available variable, which is updated by a Timer Callback.
I2C1 is availailable and its PIN configuration is attached. Data transfer via UART is already working.
The microcontroller is intended to be an I2C slave.
Use of I2C HAL DMA is recommended.
The value shall be returned differently, depending on the command sent from the calling master. Therefore 3 simple routines shall be created - each one for the 3 different commands.
Given "M" is master, "S" is slave, "A" is the variable on the slave device, C1..C3 are different commands over I2C and "R" are returned bytes by slave
Example scheme like:
M -> S (initiating I2C traffic by calling the address of S)
S -> M (ACK)
M -> S (sending command byte C1 or C2 or C3)
S -> M (sending R as a series of bytes, depending on how the command is interpreted. In this project, just send the value A one time when C1 is sent, two times if C2 is sent and 3 times if command C3 is sent by the master. like: in case C1 return "A" in case C2 return "AA", in case command C3 is sent from master to slave, slave returns "AAA")
this should be a very simple I2C connection.
I2C1 is availailable and its PIN configuration is attached. Data transfer via UART is already working.
The microcontroller is intended to be an I2C slave.
Use of I2C HAL DMA is recommended.
The value shall be returned differently, depending on the command sent from the calling master. Therefore 3 simple routines shall be created - each one for the 3 different commands.
Given "M" is master, "S" is slave, "A" is the variable on the slave device, C1..C3 are different commands over I2C and "R" are returned bytes by slave
Example scheme like:
M -> S (initiating I2C traffic by calling the address of S)
S -> M (ACK)
M -> S (sending command byte C1 or C2 or C3)
S -> M (sending R as a series of bytes, depending on how the command is interpreted. In this project, just send the value A one time when C1 is sent, two times if C2 is sent and 3 times if command C3 is sent by the master. like: in case C1 return "A" in case C2 return "AA", in case command C3 is sent from master to slave, slave returns "AAA")
this should be a very simple I2C connection.