summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Naik2020-04-03 19:18:28 -0400
committerAditya Naik2020-04-03 19:18:28 -0400
commitbf4fadd261d45c3389d689d62730175e5357ff90 (patch)
tree1c17e58115fc9e61c856c5732e920a0aef22778d
parent782166eb0ade59451e01cdc5fc73dd0aa60a0129 (diff)
MDR is getting received correctly but HAL states error
-rw-r--r--Src/main-hs.c41
-rw-r--r--Src/main.c9
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<MDR_len; x++) {
+ sprintf((char*)debug_buf+x, "%x", MDR_buf[x]);
+ }
+ uint8_t mdrbuf[] = "Got MDR: \n";
+ HAL_UART_Transmit(&huart1, mdrbuf, sizeof(mdrbuf), 100);
+ HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100);
+ HAL_UART_Transmit(&huart1, term, 2, 100);
+ memset(debug_buf, 0, 128);
+ goto __HS_MDR_MDR_TESTING_END;
}
__TESTING_BLOCK_END:
__asm__("nop");
@@ -350,7 +371,7 @@ __TESTING_BLOCK_END:
memset(debug_buf, 0, 128);
goto __HS_CTS_I2C_ERROR_END;
__HS_MDR_I2C_ERROR:
- sprintf((char*)debug_buf, "Unable to get MDR. I2C error: %ld\r\n", HAL_I2C_GetError(&hi2c1));
+ sprintf((char*)debug_buf, "Unable to get MDR. I2C error: %ld\n\tError counter: %ld\r\n", HAL_I2C_GetError(&hi2c1), AF_error_counter);
HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100);
memset(debug_buf, 0, 128);
goto __HS_MDR_I2C_ERROR_END;
diff --git a/Src/main.c b/Src/main.c
index d68add2..7130e8f 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -48,10 +48,10 @@
#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
+/* #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 */