This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

USART: to send more Bits

Hello,

I'm searching for a function in the Realview Compiler, where I can send more than one Bit over the USART.

__inline void AT91F_US_PutChar (
  AT91PS_USART pUSART,
  int character )
{
    pUSART->US_THR = (character & 0x1FF);
}

e.g. I have a[11] = "Hello World"; and I want to send it with

for(int i=0; i<2; i++)
        {
           AT91F_US_PutChar (COM0,a[i]);
        }

But with this version, only the last Bit (e.g. o) will be transmitted. What would be the reason for this?

best regards
Bernd

Parents
  • If I read the documentation correctly, BFC_MR is Burst Flash Controller Mode Register. I have not read the datasheet thoroughly, but I would assume that this register doesn't have anything to do with the USART.

    The USART status bits can be found in the USART Channel Status Register (US_CSR).

    Also, the code snippet is a bit confusing. There's a commented-out line that refers to pUSART1, a regular line that refers to pUSART2, and then a third line that refers to COM0. That unfortunately makes it completely unclear which of the USART interfaces (according to the documentation, the chip has four of them) your are trying to work with.

Reply
  • If I read the documentation correctly, BFC_MR is Burst Flash Controller Mode Register. I have not read the datasheet thoroughly, but I would assume that this register doesn't have anything to do with the USART.

    The USART status bits can be found in the USART Channel Status Register (US_CSR).

    Also, the code snippet is a bit confusing. There's a commented-out line that refers to pUSART1, a regular line that refers to pUSART2, and then a third line that refers to COM0. That unfortunately makes it completely unclear which of the USART interfaces (according to the documentation, the chip has four of them) your are trying to work with.

Children
  • thank you for your reply. I work with the UART1.

    #define pUSART2 ((AT91PS_BFC) AT91C_PB26_RTS1)
    
    
    #define MCK     60000000
    
    
    AT91PS_USART COM0;
    
    void initialize()
    {
    
            COM0= AT91C_BASE_US1;
    
            /* Define RXD and TXD as peripheral             */
        AT91F_PIO_CfgPeriph(AT91C_BASE_PIOB,AT91C_PB21_RXD1 | AT91C_PB20_TXD1 | AT91C_PB26_RTS1,0);
    
            // First, enable the clock of the PIOB
            AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1<<AT91C_ID_US1 ) ;
    
            // Usart Configure
            AT91F_US_Configure (COM0, MCK,AT91C_US_ASYNC_MODE, 115200, 0);
    
            // Enable usart
            COM0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
    
            AT91F_US_PutChar (COM0,'X');
    
    }
    
    
    void uart (void)
    {
    
            char  a[11] = "Hallo Welt";
    
    
    
            initialize();
    
            for(int i=0; i<11; i++)
            {
               while( !(COM0->US_CSR  & AT91C_US_TXRDY) );
    
               AT91F_US_PutChar (COM0,a[i]);
            }
    }
    

    That's all of my code - but it doesn't run correctly.

    best regards
    Bernd

  • now it works... but could you explain to me the following code lines:

    COM1->US_THR = (a[i] & 0xFF);
    

    What's the meaning of 0xFF (1111 1111)? What's the reason for this?

    and the second line:

    AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1<<AT91C_ID_US1 ) ;
    

    What's the meaning of 1<<AT91C_ID_US1? US1 ID is 7. So it's a bit-operation which sets the number 1 at the 7te position.

    best regards
    Bernd

  • I KEEP GETTING FATAL ERROR WHEN I TYPE A51 AT MY COMMAND LINE.

    WHY?

  • What's the meaning of 0xFF (1111 1111)? What's the reason for this?

    There shouldn't be a pressing reason to set the top 24 bits of the word written to the USART to 0. The USART should only process as many bits as it is configured to do, and ignore the rest.

    What's the meaning of 1<<AT91C_ID_US1? US1 ID is 7. So it's a bit-operation which sets the number 1 at the 7te position.

    7 is the peripheral ID of USART1 (see device datasheet, p. 21). The peripheral clock to device 7 is enabled by writing 0x00000080 to the PMC_PCER (see device datasheet, p. 280).