According to the AT91SAM7S256 datasheet (page295-296), the UART gets a hardware handshaking mode (RTS/CTS flow control). I used the Hyperterminal to test it but failed.
My code is as follows:
void Usart_init ( void )
{
COM0= AT91C_BASE_US0;
AT91F_PIO_CfgPeriph(
AT91C_BASE_PIOA, // PIO controller base address
((unsigned int) AT91C_PA5_RXD0 ) |
((unsigned int) AT91C_PA8_CTS0 ) |
((unsigned int) AT91C_PA7_RTS0 ) |
((unsigned int) AT91C_PA6_TXD0 ), // Peripheral A
0); // Peripheral B ;
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1<<AT91C_ID_US0 ) ;
// Usart Configure
AT91F_US_Configure (COM0, MCK,AT91C_US_ASYNC_MODE_HW,USART_BAUD_RATE , 0);
//I defined AT91C_US_ASYNC_MODE_HW in library
// Enable usart
COM0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
AT91F_PDC_Open (AT91C_BASE_PDC_US0);
COM0->US_RTOR = 0xFFFF;
COM0->US_RPR = (unsigned int)receive;
COM0->US_RCR = 8;
}
void main(void)
{
Usart_init();
while(1){
AT91F_US_ReceiveFrame (COM0, receive, 8, 0,0 );
while (AT91F_PDC_IsRxEmpty (AT91C_BASE_PDC_US0)==0){}
AT91F_US_SendFrame(COM0, receive,8,0,0);
while (AT91F_PDC_IsTxEmpty (AT91C_BASE_PDC_US0)==0){}
}
}
This code is basically to receive a data buffer from Hyperterminal and echo back.
The Hyperterminal is set in Hardware Flow Control mode.
However, the UART could not receive anything from PC after I typed some characters in the Hyperterminal window. I probed the RTS0 pin (PA7) using oscilloscope and found that this pin was low (which was active). RTS low indicated to the remote device that it could start transmitting. So the UART was supposed to receive the buffer. Moreover, I used the PDC channel for reception as the datasheet stated.
I have no idea why it does not work! All followed the datasheet. Anyone knows the RTS/CTS flow control can give me some hints?