summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Naik2020-03-24 17:14:54 -0400
committerAditya Naik2020-03-24 17:14:54 -0400
commitba94542d42014b8b8929b2b4ea9a17a213cd6230 (patch)
tree587c323dc8fef83611182610a7db03eda041449a
parent553d9c7d470dcf2dadbfefb409cb13314c79fd9d (diff)
s2m ACK works but errors out after some time
-rw-r--r--.gitignore1
-rw-r--r--Src/main.c32
2 files changed, 28 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 554ca6b..10e9fff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,5 +10,6 @@ uctrl-firmware.txt
.mxproject
*.o
*.bin
+*~
src/
MDK-ARM/ \ No newline at end of file
diff --git a/Src/main.c b/Src/main.c
index 5f626dd..652fc8b 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 ---------------------------------------------------------*/
@@ -158,6 +158,27 @@ int main(void)
while (HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)I2C_ADDRESS, (uint8_t*)MDR_req_buf, 2, 10000) != HAL_OK);
HAL_GPIO_TogglePin(led_GPIO_Port, led_Pin);
+ while (HAL_I2C_Master_Receive(&hi2c1, (uint8_t)I2C_ADDRESS, (uint8_t*)MDR_req_buf, 2, 10000) != HAL_OK);
+
+ uint8_t bufbuf2[] = "MDR ACK buffer: ";
+ HAL_UART_Transmit(&huart1, bufbuf2, sizeof(bufbuf2), 100);
+ for(int x=0; x<2; x++) {
+ sprintf((char*)debug_buf+x, "%x", MDR_req_buf[x]);
+ }
+ HAL_UART_Transmit(&huart1, debug_buf, 2, 100);
+ HAL_UART_Transmit(&huart1, term, 2, 100);
+ memset(debug_buf, 0, 128);
+
+
+ pb_istream_t MDR_ACK_istream = pb_istream_from_buffer(MDR_req_buf, 2);
+ s2m_MDR_req_ACK MDR_ACK;
+ pb_decode(&MDR_ACK_istream, s2m_MDR_req_ACK_fields, &MDR_ACK);
+#ifdef TESTING_ENABLE
+ sprintf((char*)debug_buf, "Got MDR message length: %ld\r\n", MDR_ACK.MDR_res_length);
+ HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100);
+ memset(debug_buf, 0, 128);
+#endif /* TESTING_ENABLE */
+
#else /* MASTER */
uint8_t buffer[128], debug_buf[128], term[]="\r\n";
size_t MDR_enc_size;
@@ -194,7 +215,7 @@ int main(void)
memset(debug_buf, 0, 128);
#endif
- uint8_t MDR_ACK_buf[64];
+ uint8_t MDR_ACK_buf[8];
s2m_MDR_req_ACK ack;
ack.MDR_res_length = MDR_enc_size;
pb_ostream_t MDR_ack_ostream = pb_ostream_from_buffer(MDR_ACK_buf,
@@ -228,10 +249,10 @@ int main(void)
}
#ifdef TESTING_ENABLE
- uint8_t bufbuf2[] = "MDR req buffer: ";
+ uint8_t bufbuf2[] = "MDR ACK buffer: ";
HAL_UART_Transmit(&huart1, bufbuf2, sizeof(bufbuf2), 100);
for(int x=0; x<2; x++) {
- sprintf((char*)debug_buf+x, "%x", MDR_req_buf[x]);
+ sprintf((char*)debug_buf+x, "%x", MDR_ACK_buf[x]);
}
HAL_UART_Transmit(&huart1, debug_buf, MDR_enc_size, 100);
HAL_UART_Transmit(&huart1, term, 2, 100);
@@ -254,7 +275,8 @@ int main(void)
#endif /* TESTING_ENABLE */
HAL_GPIO_TogglePin(led_GPIO_Port, led_Pin);
-
+
+ HAL_I2C_Slave_Transmit(&hi2c1, (uint8_t*)MDR_ACK_buf, 2, 10000);
#endif /* MASTER */
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */