2019-03-19 09:25 AM
I am trying to communicate with a Nucleo_L476RG development board through I2C from an Arduino Uno. However I am having difficulty communicating more than one data frame. The first frame will accept the address and the data, afterwards it will not acknowledge the same address. I have used the I2C_TwoBoards_ComRestartIT example as a reference and have included the necessary 3.3 kohm pull up resistors in the transmission lines. The only real change that I have made is converting the example to 7-bit addressing mode and the master is an Arduino Uno.
First Frame of Data after Reset
Next Frame of Data
Code
if(HAL_I2C_EnableListen_IT(&hi2c1) != HAL_OK)
{
Error_Handler();
}
while(uwTransferRequested != 1)
{
}
if(HAL_I2C_Slave_Sequential_Receive_IT(&hi2c1, (uint8_t *)aRxBuffer, RXBUFFERSIZE,I2C_FIRST_FRAME) != HAL_OK)
{
Error_Handler();
}
while(HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_LISTEN)
{
}
while(uwTransferRequested != 1) {}
if(HAL_I2C_Slave_Sequential_Transmit_IT(&hi2c1, (uint8_t*)aTxBuffer, TXBUFFERSIZE,I2C_LAST_FRAME) != HAL_OK)
{
Error_Handler();
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY) {}
if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE)) Error_Handler();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);
HAL_Delay(250);
/* USER CODE BEGIN 3 */
}
Arduino Code
#include <Wire.h>
byte val[4] = {0x04, 0x05, 0x05, 0x06};
byte success = 0;
byte data[4];
void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Wire.beginTransmission(0x33);
for (int i = 0; i <=3; i++){
Wire.write(val[i]);
}
success = Wire.endTransmission();
Serial.println(success);
delay(1000);
}
Any help would be greatly appreciated