//My code------------------------------
char ch_Data[5];
void SystemClock_Config(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_CAN_Init();
MX_USART1_UART_Init();
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
BSP_LED_Init(LED5);
BSP_LED_Init(LED6);
__HAL_RCC_CLEAR_RESET_FLAGS();
MX_IWDG_Init();
while (1)
{
strcat(ch_Data,"D");
strcat(ch_Data,"E");
strcat(ch_Data,"S");
strcat(ch_Data,"G");
strcat(ch_Data,"I");
strcat(ch_Data,"N");
HAL_UART_Transmit(&huart1, (uint8_t*)ch_Data, sizeof(ch_Data), 6);
HAL_Delay(100);
WWDG_Feed();
BSP_LED_Toggle(LED3);
HAL_Delay(100);
BSP_LED_Toggle(LED4);
HAL_Delay(100);
}
}
//-------------------------------------------------------------------------
Thanks for reply!Hi,
With PIC you use a (NUL terminated) string. But here you use an array of bytes. Since this is not NULL terminated you need to say how many (sizeof) bytes you want to send.
Just define an array of uint8_t where you store the text.
There are many examples around.
Did you do an internet search about "HAL UART usage", or "HAL UART example" ?
Klaus
while (1)
{
uint8_t buffer[5];
strcat(buffer,"A");
strcat(buffer,"B");
strcat(buffer,"C");
strcat(buffer,"D");
strcat(buffer,"E");
HAL_UART_Transmit(&huart1, buffer, sizeof(buffer), HAL_MAX_DELAY);
HAL_Delay(100);
WWDG_Feed();
}
}
...
uint8_t buffer[5];
...
buffer[0] = "A";
buffer[1] = "B";
buffer[2] = "C";
buffer[3] = "D";
buffer[4] = "E";
...
while (1)
{
HAL_UART_Transmit(&huart1, buffer, sizeof(buffer), HAL_MAX_DELAY);
HAL_Delay(100);
WWDG_Feed();
}
}
Would you be so kind to tell "what" error you get?but its giving me error!
Hi,
Would you be so kind to tell "what" error you get?
Klaus
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
/* Get RX message */
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK)
{
/* Reception Error */
Error_Handler();
}
if ((RxHeader.StdId == 0x321) && (RxHeader.IDE == CAN_ID_STD) && (RxHeader.DLC == 8))
{
BSP_LED_ON(LED4); // steady on means no can tx/rx
HAL_Delay(50);
}
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_CAN_Init();
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
__HAL_RCC_CLEAR_RESET_FLAGS();
MX_IWDG_Init();
while (1)
{
WWDG_Feed();
BSP_LED_On(LED3); // steady on means no can tx/rx
HAL_Delay(50);
HAL_CAN_RxFifo0MsgPendingCallback(&hcan);
}
Hi,
still unclear what the problem is.
You don´t give useful infromations.
Klaus
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_CAN_Init();
__HAL_RCC_CLEAR_RESET_FLAGS();
MX_IWDG_Init();
while (1)
{
WWDG_Feed();
HAL_Delay(50);
HAL_CAN_RxFifo0MsgPendingCallback(&hcan);
WWDG_Feed();
if (RxHeader.StdId == 0x235)
{
HAL_UART_Transmit_IT(&huart1, RxData, 8);
HAL_Delay(1000);
}
if (RxHeader.StdId == 0x297)
{
HAL_UART_Transmit_IT(&huart1, RxData, 8);
HAL_Delay(1000);
}
}
}
Thanks For reply.Hi,
we still don´t see what you expect and what you see instead.
ASCII is a byte, HEX is a byte.
If you can send a byte, then you can send an ASCII character and then you can olso send an HEX byte.
try to send a single byte in different ways via UART to your Terminal:
* Send "M"
* Send 0x4D
* Send 77
* Send 0b01001101
with all four examples you send identical code via UART. Nothing different. It´s all the same. You need to accept and understand this.
How the Terminal displays the received data is a Terminal setup issue, not a software issue, not a UART issue..
****
Why don´t you
* clearly say what Terminal software you use
* show your Terminal setup
* show Terminal screenshot
* show what you expect
* give examples of what you expect and what you get instead
Klaus
int hex_to_ascii(int c){
int high;
int low;
high = (c >>4);
low = (c and 0x0F);
if (high < 10){
high = high + "0";}
else {
high = high - 10 + "A";}
if (low < 10){
low = low + "0";}
else {
low = low - 10 + "A";}
UART_sendByte (high);
UART_sendByte (low);
UART_sendByte (" ");
return;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?