We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
Does AT91F_US_PutChar() actually check if the UART is ready to transmit another character, i.e. if it has finished transmitting the previous character ?
I think it doesn't.
I try to use this.
for(int i=0; i<11; i++) { // while( !(pUSART1->US_CSR & AT91C_US_TXRDY) ); while( !(pUSART2->BFC_MR & AT91C_US_TXRDY) ); AT91F_US_PutChar (COM0,a[i]); }
But it's still the same result. I work with the RM9200 from Atmel.
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.
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.
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.
I KEEP GETTING FATAL ERROR WHEN I TYPE A51 AT MY COMMAND LINE.
WHY?
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.
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).