From bf4fadd261d45c3389d689d62730175e5357ff90 Mon Sep 17 00:00:00 2001 From: Aditya Naik Date: Fri, 3 Apr 2020 19:18:28 -0400 Subject: MDR is getting received correctly but HAL states error --- Src/main-hs.c | 41 +++++++++++++++++++++++++++++++---------- Src/main.c | 9 +++++++-- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Src/main-hs.c b/Src/main-hs.c index 68aed8b..0fe8783 100644 --- a/Src/main-hs.c +++ b/Src/main-hs.c @@ -48,7 +48,7 @@ #define SET_BIT_FROM_IDX(a, b) a[b>>5]|=(1<<(b%32)) #define COUNTOF(__BUFFER__) (sizeof(__BUFFER__) / sizeof(*(__BUFFER__))) -#define I2C_ADDRESS 0x05 +#define I2C_ADDRESS 0x30F /* Macro to toggle between master and slave firmware */ #define MASTER @@ -124,7 +124,9 @@ int main(void) /* Handshake variables */ uint8_t hs_sts = IDLE; uint8_t debug_buf[128], term[] = "\r\n"; - uint8_t *MDR_req_buf, *MDR_ACK_buf, *MDR_CTS_buf, *MDR_buf; + uint8_t *MDR_req_buf, *MDR_ACK_buf, *MDR_CTS_buf;/* , *MDR_buf; */ + uint8_t MDR_buf[256]; + uint32_t AF_error_counter = 0; size_t MDR_req_size, MDR_CTS_size; m2s_MDR_request MDR_req_message; @@ -173,7 +175,7 @@ int main(void) case (HS_MDR_ACK): { MDR_ACK_buf = malloc(8); - uint32_t AF_error_counter = 0; + AF_error_counter = 0; 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) { @@ -234,7 +236,7 @@ int main(void) __HS_MDR_CTS_TESTING_END: __asm__("nop"); #endif - if (HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)I2C_ADDRESS, + if (HAL_I2C_Master_Transmit(&hi2c1, (uint8_t)I2C_ADDRESS, (uint8_t*)MDR_CTS_buf, 2, 10000) != HAL_OK) { hs_sts = HS_FAILED; goto __HS_CTS_I2C_ERROR; @@ -250,17 +252,18 @@ int main(void) } case (HS_MDR_MDR): { - MDR_buf = (uint8_t*)malloc(MDR_len); - uint32_t AF_error_counter = 0; + /* MDR_buf = (uint8_t*)malloc(MDR_len); */ + HAL_GPIO_TogglePin(led_GPIO_Port, led_Pin); + AF_error_counter = 0; while (HAL_I2C_Master_Receive(&hi2c1, (uint8_t)I2C_ADDRESS, (uint8_t*)MDR_buf, MDR_len, 1000) != HAL_OK) { if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF) { hs_sts = HS_FAILED; } - if (++AF_error_counter > 1500) { + else if (++AF_error_counter > 1500) { hs_sts = HS_FAILED; } - if (hs_sts == HS_FAILED) { + if (hs_sts == HS_FAILED) { #ifdef DEBUG_ENABLE goto __HS_MDR_I2C_ERROR; __HS_MDR_I2C_ERROR_END: @@ -269,7 +272,15 @@ int main(void) break; } } - // TODO Decode the MDR + /* if (hs_sts != HS_FAILED) { */ + // TODO Decode the MDR +#ifdef TESTING_ENABLE + goto __HS_MDR_MDR_TESTING; + __HS_MDR_MDR_TESTING_END: + __asm__("nop"); +#endif + /* } */ + break; } @@ -311,6 +322,16 @@ int main(void) HAL_UART_Transmit(&huart1, term, 2, 100); memset(debug_buf, 0, 128); goto __HS_MDR_CTS_TESTING_END; + __HS_MDR_MDR_TESTING: + for (int x=0; x>5]|=(1<<(b%32)) #define COUNTOF(__BUFFER__) (sizeof(__BUFFER__) / sizeof(*(__BUFFER__))) -#define I2C_ADDRESS 0x05 +#define I2C_ADDRESS 0x30F /* Macro to toggle between master and slave firmware */ -#define MASTER +/* #define MASTER */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ @@ -416,6 +416,11 @@ int main(void) memset(debug_buf, 0, 128); #endif /* DEBUG_ENABLE */ } + else { + sprintf((char*)debug_buf, "Successfully sent MDR\r\n"); + HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100); + memset(debug_buf, 0, 128); + } #endif /* MASTER */ -- cgit v1.2.3