summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Naik2020-03-25 16:53:27 -0400
committerAditya Naik2020-03-25 16:53:27 -0400
commit45fd36f9217301a85b774fdb2ede7f8e29f0e3c7 (patch)
treedcbaf58284248a5d1da579a3ef95d6a576177c89
parentb26368979741bd936f0dbbf037ef8ec5d03d2338 (diff)
Resetting communication after AF error
-rw-r--r--Src/main.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Src/main.c b/Src/main.c
index 1afa688..6f7f8a4 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -51,7 +51,7 @@
#define I2C_ADDRESS 0x30F
/* Macro to toggle between master and slave firmware */
-/* #define MASTER */
+#define MASTER
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
@@ -157,15 +157,17 @@ int main(void)
uint8_t MDR_ACK_buf[8] = {0};
HAL_Delay(100);
- if (HAL_I2C_Master_Receive(&hi2c1, (uint8_t)I2C_ADDRESS, (uint8_t*)MDR_ACK_buf, 3, 10000) != HAL_OK) {
+ while (HAL_I2C_Master_Receive(&hi2c1, (uint8_t)I2C_ADDRESS, (uint8_t*)MDR_ACK_buf, s2m_MDR_req_ACK_size, 100) != HAL_OK) {
+ if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF) {
#ifdef DEBUG_ENABLE
sprintf((char*)debug_buf, "Unable to get MDR ACK. I2C error: %ld\r\n", HAL_I2C_GetError(&hi2c1));
HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100);
memset(debug_buf, 0, 128);
#endif /* DEBUG_ENABLE */
+ break;
+ }
}
-
#ifdef TESTING_ENABLE
uint8_t bufbuf2[] = "MDR ACK buffer: ";
HAL_UART_Transmit(&huart1, bufbuf2, sizeof(bufbuf2), 100);
@@ -292,7 +294,7 @@ int main(void)
HAL_GPIO_TogglePin(led_GPIO_Port, led_Pin);
- if (HAL_I2C_Slave_Transmit(&hi2c1, (uint8_t*)MDR_ACK_buf, 2, 10000) != HAL_OK) {
+ if (HAL_I2C_Slave_Transmit(&hi2c1, (uint8_t*)MDR_ACK_buf, s2m_MDR_req_ACK_size, 10000) != HAL_OK) {
#ifdef DEBUG_ENABLE
sprintf((char*)debug_buf, "Unable to send MDR ACK. I2C error: %ld\r\n", HAL_I2C_GetError(&hi2c1));
HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100);