mx rt 1020 send 9bit over DMA

cancel
Showing results for 
Search instead for 
Did you mean: 

mx rt 1020 send 9bit over DMA

Jump to solution
193 Views
bp1979
Contributor IV

Hi 

I am using an imx rt 1020 and try to send 9bit data over dma, but having trouble sending the 9th bit.

 

status_t LPUART_SendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer)

 

 

the lpuart_transfer_t is defined as follows

 

typedef struct _lpuart_transfer
{
    uint8_t *data;   /*!< The buffer of data to be transfer.*/
    size_t dataSize; /*!< The byte count to be transfer. */
} lpuart_transfer_t;

 

I tried to split uint16_t bytes in two bytes and sent that over, but it doesn't work.

 

        uint32_t txIndex = 0;
        for (uint32_t i = 0; i < length; i++)
        {
                // T == uint16_t 
        	T d = data[i];

        	if (sizeof(T) == 2)
        	{
                _txBuffer[txIndex++] = d & 0xFF ;
                _txBuffer[txIndex++] = (d & 0x100) >> 8 ;
        	}
        	else
        	{
        		_txBuffer[txIndex++] = d;
        	}
        }

        _sendXfer.data = _txBuffer;
        _sendXfer.dataSize = length;
        

        LPUART_SendEDMA(_instance, &_uartDmaHandle, &_sendXfer);

 

 

this sends 

bp1979_0-1634911199353.png

but is should send one "9bit byte" 0x108.

I am obviously doing this wrong, how can I send 9bits over DMA?

 

 

0 Kudos
1 Solution
112 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

Hope you are well and I apologize for my delayed reply.
Commonly the 9bit is used to send the parity bit and have 8 bits of data, this can be done in the example without the need of setting anything extra besides the 9th bit and parity enable.
I did some modifications to the example so it supports the 9bith data without parity:

1. Modified the data types from structure "lpuart_transfer_t" so the uint´s are of 16bits.

Omar_Anguiano_0-1636076857352.png

2. In LPUART_SendEDMA() modified the parameters from EDMA_PrepareTransfer() function, the parameters I modified are bytesEachRequest and transferBytes:

Omar_Anguiano_1-1636076877119.png
Here are my results:

Omar_Anguiano_2-1636076909711.png
Notes: xfer.dataSize needs to be in multiples of 2. If you write 4 to that variable then 2 9bit LPUART frames are sent.

Let me know if this is helpful, if you have more questions do not hesitate to ask me.
Best regards,
Omar

View solution in original post

4 Replies
113 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

Hope you are well and I apologize for my delayed reply.
Commonly the 9bit is used to send the parity bit and have 8 bits of data, this can be done in the example without the need of setting anything extra besides the 9th bit and parity enable.
I did some modifications to the example so it supports the 9bith data without parity:

1. Modified the data types from structure "lpuart_transfer_t" so the uint´s are of 16bits.

Omar_Anguiano_0-1636076857352.png

2. In LPUART_SendEDMA() modified the parameters from EDMA_PrepareTransfer() function, the parameters I modified are bytesEachRequest and transferBytes:

Omar_Anguiano_1-1636076877119.png
Here are my results:

Omar_Anguiano_2-1636076909711.png
Notes: xfer.dataSize needs to be in multiples of 2. If you write 4 to that variable then 2 9bit LPUART frames are sent.

Let me know if this is helpful, if you have more questions do not hesitate to ask me.
Best regards,
Omar

View solution in original post

44 Views
bp1979
Contributor IV

@Omar_Anguiano  Thank you very much! Took me a while before I could dip into this, but  finally got  this to work!  

0 Kudos
153 Views
bp1979
Contributor IV

Dear nxp

Would anybody care to give some guidance? How do i send 9bit over lpuart using dma? 

0 Kudos
149 Views
bp1979
Contributor IV

Dear NXP

if there is any better way, please let me know. For now just went for a hacky blocking write

    virtual void Write(T *data, uint32_t length)
    {
        projectAssert(sizeof(_txBuffer) > length, ErrorCodeUartTxMessageTooLarge);

        if (sizeof(T) == 2)
        {
            // If T is uint16_t, write to uart blocking
            // Waiting for answer how to send 9bit data over uart with DMA
        	// https://community.nxp.com/t5/i-MX-RT/mx-rt-1020-send-9bit-over-DMA/td-p/1360134
        	for (uint32_t i=0; i<length; i++)
        	{
        		while (!(_instance->STAT & LPUART_STAT_TDRE_MASK))
        		{
        			// Wait for transmit ready
        		}
                uint32_t temp = _instance->DATA & 0xFFFFFC00UL;
                temp |= (uint32_t)data[i];
                _instance->DATA = temp;
        	}
        }
        else if (sizeof(T) == 1)
        {
        	// Else... regular send data over DMA
            xSemaphoreTake(_txSemaphore, portMAX_DELAY);

            for (uint32_t i = 0; i < length; i++)
            {
                _txBuffer[i] = data[i];
            }

            _sendXfer.data = _txBuffer;
            _sendXfer.dataSize = length;

            LPUART_SendEDMA(_instance, &_uartDmaHandle, &_sendXfer);
        }
        else
        {
        	// For now we only support 8 bit and 16 bit data types
        	projectAssert(0, ErrorCodeUartUnsupportedType);
        }
    }
0 Kudos