2019-04-11 02:54 AM
This is the signature of the function:
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
where pData is the pointer to the data to be transmitted and Size the amount of data to be sent. In case of wordlength = 9bits and NO parity:
huart->TxXferSize = Size;
huart->TxXferCount = Size;
while(huart->TxXferCount > 0U)
{
huart->TxXferCount--;
if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
{
tmp = (uint16_t*) pData;
huart->Instance->TDR = (*tmp & (uint16_t)0x01FFU);
pData += 2U;
}
else
{
huart->Instance->TDR = (*pData++ & (uint8_t)0xFFU);
}
}
pData is incremented by 2 until it reaches 2 times the size of the array.. and BOOM!
Same problem with HAL_IRDA_Transmit(). With the receive the array has to be big enough (2xSize). Definetly confusing..
Solved! Go to Solution.
2019-04-15 07:17 AM
Hello,
@Bob S analysis is right : in case of 9bit data with no parity, each "item" sent/received by application is using 2 bytes in buffer provided as function parameter for HAL_UART_Transmit/Receive APIs.
So, sending/receiving a 5 items buffer requires for instance :
Agree this could be made clearer in function header (only following statement is present in code part for some series, as a comment : "/* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */). I took the point to request this to be improved in future releases.
Regards
Guenael
2019-04-11 03:20 AM
Hello,
Which Cube firmware version used ?
Regards
Imen
2019-04-11 03:21 AM
H7 v1.3.2
2019-04-11 07:38 AM
According to the function header, the "size" parameter is "amount of data to be sent". Perhaps not perfectly clear, but I interpret this as meaning the number of data "items" to be sent, NOT necessarily the size of the buffer. For 9-bit data, each "item" is, well, 9 bits, which takes 2 bytes to store. So to send 4 each 9-bit data "items", your buffer needs to hold 8 bytes, and "size" passed to HAL_UART_Transmit() should be set to 4.
2019-04-15 05:15 AM
mmm.. I see your point. Still not clear at all. Maybe "number of words to be sent" or "items", as you say, would be clearer. And maybe an additional check on the parameters wouldn't hurt...
2019-04-15 07:17 AM
Hello,
@Bob S analysis is right : in case of 9bit data with no parity, each "item" sent/received by application is using 2 bytes in buffer provided as function parameter for HAL_UART_Transmit/Receive APIs.
So, sending/receiving a 5 items buffer requires for instance :
Agree this could be made clearer in function header (only following statement is present in code part for some series, as a comment : "/* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */). I took the point to request this to be improved in future releases.
Regards
Guenael