cancel
Showing results for 
Search instead for 
Did you mean: 

9-BIT UART TRANSMISSION

msingh08
Associate II

Hi, 

 

I'm attempting to use UART3 on a STM32L431CC to transmit 9 bit data, I've created the following code after reading https://community.st.com/t5/stm32-mcus-products/9-bit-uart-transmission-stm32-cubemx-hal-driver/m-p/327138

 

With the code below I am indeed able to transmit the correct data however it sends every other request, however if I change the variable type to be "uint8_t byte" the data (wrong) is sent at every request. I'm unsure what I'm doing wrong but is there any other way I can set the 9th bit? 

 

Thanks in advance. 

 

 

uint8_t pkt_size = getPktSize( *pPkt );

static uint16_t byte[6] = {0};	//the size of this array depends on the max reply size currently 6 (pktData)

HAL_UART_AbortReceive_IT(Uartx);				//abort any previous receive (interrupt)

	for (int var = 0; var < pkt_size; var++)
	{
		if(var == 0)
		{
			byte[var] = (*pPkt++) | 1<<8; // 1st byte of the packet
		}

		else
		{
			byte[var] = (*pPkt++) & 0x00ff;
		}
	}

	RS485_Enable_tx();	//Enable RS485 transmission mode

    HAL_UART_Transmit_IT(&huart3, byte, pkt_size);

 

 

 

//Method 2
	if (the_txChannel.pNext == the_txChannel.pBegin) // 1st byte of the packet
    {
		Set_byte_Transmit_completed(false);
		byte = *the_txChannel.pNext++ | 1<<8;
		HAL_UART_Transmit_IT(&huart3, (uint8_t *)&byte, 1);
    }

    else if (the_txChannel.pNext < the_txChannel.pEnd)
    {
    	Set_byte_Transmit_completed(false);
		HAL_UART_Transmit_IT(&huart3, the_txChannel.pNext++, 1);

    }

    else
    {
    	while(!Frame_Transmit_completed);
    	RS485_Disable_tx();
        the_txChannel.callback();
    }

 

 

0 REPLIES 0