i2c dma transmit/receive multiple bytes
I am trying to transmit multiple bytes on I2C bus using dma. In the sample code I am trying to send 3 bytes. I see on my scope that three bytes are being sent but the problem is that the first byte gets sent three times. I am also able to recive three bytes without any problem but agian nothing gets written in the location of the second and third byte.
I generated the code using CubeMX but modified the main file to send/recieve at the right time. My master transmitter code looks like this:#define
i2c_buffer_size 3
uint8_t
i2c_data_buffer[i2c_buffer_size] = {0x03,0x10,
0xFF};
uint16_t slaveAddress =
0x05;
....
void
cmd_send_i2c(
){
HAL_I2C_Master_Transmit_DMA(&hi2c1, slaveAddress,i2c_data_buffer, i2c_buffer_size);
}
My slave receiver code looks like this
</p>
int
</b>
main(
void
){
/* Reset of all peripherals, Initializes the Flash interface and the
Systick
. */
HAL_Init();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_I2C1_Init();
while
(1)
{
if
(HAL_I2C_GetState(&hi2c1)==
HAL_I2C_STATE_READY
)
HAL_I2C_Slave_Receive_DMA(&hi2c1,(
uint8_t
*) i2c_data_buffer,i2c_buffer_size);
}
return
0;}
and the receive call back function is
void
HAL_I2C_SlaveRxCpltCallback(
I2C_HandleTypeDef
*hi2c){
LED_RED_TOGGLE;
if
(i2c_data_buffer[0] == 0x03)
LED_BLUE_TOGGLE;
if
(i2c_data_buffer[1] == 0x10)
LED_GREEN_TOGGLE;
return
;
}
I am checking the i2c_data_buffer using a debugger and the value for i2c_data_buffer[0] is correct but i2c_data_buffer[1] is not correct.
Thanks in advance for the help!