Skip to content

Commit

Permalink
more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Apr 26, 2024
1 parent 078db26 commit beec2c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
33 changes: 22 additions & 11 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,19 @@ int main(void)
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
HAL_Delay(3);
float voltage = 10.0; // V
float current = 1.0; // A
uint8_t voltage_high = ((uint16_t) (voltage * 10)) >> 8;
uint8_t voltage_low = (uint8_t) voltage * 10;
uint8_t current_high = ((uint16_t) (current * 10)) >> 8;
uint8_t current_low = (uint8_t) (current * 10);
uint8_t control = 1; // 0 for start charging
//uint8_t charger_msg[8] = {0, 0, 0, control, current_low, current_high, voltage_low, voltage_high};
uint8_t charger_msg[8] = {voltage_high, voltage_low, current_high, current_low, control, 0, 0, 0};
HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, charger_msg);
HAL_Delay(1);
// if (get_switch(gpio, SWITCH_PIN_1) == 0) {
uint8_t charger_msg[8] = {0, 0, 0, control, current_low, current_high, voltage_low, voltage_high};
// uint8_t charger_msg[8] = {voltage_high, voltage_low, current_high, current_low, control, 0, 0, 0};
// HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, charger_msg);
// HAL_Delay(1);
// // if (get_switch(gpio, SWITCH_PIN_1) == 0) {
// if (state_idx + 1 == display_state_count) {
// state_idx = 0;
// } else {
Expand Down Expand Up @@ -379,7 +380,7 @@ static void MX_USART2_UART_Init(void)
/* USER CODE END USART2_Init 2 */

}
#include <stdlib.h>

/**
* @brief GPIO Initialization Function
* @param None
Expand Down Expand Up @@ -421,7 +422,7 @@ int _write(int fd, char *ptr, int len)
HAL_UART_Transmit(&huart2, (uint8_t *)ptr, len, HAL_MAX_DELAY);
return len;
}

#include <stdlib.h>
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
if ((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET)
Expand All @@ -444,21 +445,31 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
printf("I2C Write fail\r\n");
}
}
} else if (rx_header.Identifier == 0x18FF50E5) {
} else if (rx_header.Identifier == 0x1806E5F4) {
printf("Shep can msg received\r\n");
printf("%d\r\n", rx_data[0]);
printf("%d\r\n", rx_data[1]);
printf("%d\r\n", rx_data[2]);
printf("%d\r\n", rx_data[3]);
printf("%X\r\n", rx_data[4]);
printf("%d\r\n", rx_data[5]);
printf("%d\r\n", rx_data[6]);
printf("%d\r\n", rx_data[7]);
printf("%d\r\n\n", rx_data[7]);
} else if (rx_header.Identifier == 0x18FF50E5) {
// printf("%d\r\n", rx_data[0]);
// printf("%d\r\n", rx_data[1]);
// printf("%d\r\n", rx_data[2]);
// printf("%d\r\n", rx_data[3]);
// printf("%X\r\n", rx_data[4]);
// printf("%d\r\n", rx_data[5]);
// printf("%d\r\n", rx_data[6]);
// printf("%d\r\n\n", rx_data[7]);
FDCAN_ProtocolStatusTypeDef *protocol = malloc(sizeof(FDCAN_ProtocolStatusTypeDef));
if (HAL_FDCAN_GetProtocolStatus(hfdcan, protocol) != HAL_OK) {
Error_Handler();
}
printf("Error code: %ld\r\n", protocol->LastErrorCode);
printf("Data error code: %ld\r\n", protocol->DataLastErrorCode);
printf("Data error code: %ld (7 is no change)\r\n", protocol->DataLastErrorCode);
printf("Passive error code: %ld\r\n", protocol->ErrorPassive); // 0 active error, 1 passive
printf("Bus off : %ld\r\n\n", protocol->BusOff); // 0 for bus on, 1 bus off

Expand All @@ -470,7 +481,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
// printf("Battery connection fault: %s\r\n", ((rx_data[5] & 0b00001000) > 1) ? "True" : "False");
// printf("Communication timeout: %s\r\n", ((rx_data[5] & 0b00010000) > 1) ? "True" : "False");
} else {
printf("CAN msg %lu received \r\n", rx_header.Identifier);
printf("CAN msg %X received \r\n", rx_header.Identifier);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [4.3.0-B58] date: [Thu Apr 25 02:07:47 EDT 2024]
# File automatically-generated by tool: [projectgenerator] version: [4.3.0-B58] date: [Thu Apr 25 22:38:34 EDT 2024]
##########################################################################################################################

# ------------------------------------------------
Expand Down

0 comments on commit beec2c7

Please sign in to comment.