I have started playing with my 60 again and am having an interesting issue, when I step through my code it is fine, but if i run it it errors. I am just doing a simple echo through hyperterm.
while(1)
{
if(usart_IsDataAvailable(AT91C_BASE_US1))
{
print = usart_read_ascii(AT91C_BASE_US1);
usart_print_char(AT91C_BASE_US1, print);
}
}
this is on the olimex 9260 board and I have used this setup in the past, any ideas?
er, a hint about the UART I/O code you’re using?
unsigned char usart_IsDataAvailable(AT91S_USART *usart)
{
if ((usart->US_CSR & AT91C_US_RXRDY) != 0) {
return 1;
}
else {
return 0;
}
}
char usart_read_ascii (AT91S_USART *usart)
{
char input;
while (!(usart->US_CSR & AT91C_US_RXRDY));
input = (char)usart->US_RHR;
return input;
}
void usart_print_char (AT91S_USART *usart, char x)
{
while (!(usart->US_CSR & AT91C_US_TXRDY));
usart->US_THR = x;
}
void configure_usart1()
{
AT91C_BASE_US1->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
//AT91C_BASE_US1->US_CR = AT91C_US_RXDIS | AT91C_US_TXDIS;
/* Disable interrupts */
AT91C_BASE_US1->US_IDR = 0xFFFFFFFF;
//Setup for the ENDTX Interrupt (for DMA)
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_US1] = (unsigned long) ENDTX_handler;
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_US1] = AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE | AT91C_AIC_PRIOR_LOWEST;
AT91C_BASE_AIC->AIC_ICCR = (1 << AT91C_ID_US1);
//Enable Interrupt for ENDTX
//AT91C_BASE_US1->US_IER = AT91C_US_TXBUFE;
//AT91C_BASE_US1->US_IER = AT91C_US_ENDTX;
//AT91C_BASE_AIC->AIC_IECR = (1 << AT91C_ID_US1);
/* Configure PIOs for USART1 */
AT91C_BASE_PIOB->PIO_ASR = AT91C_PB6_TXD1 | AT91C_PB7_RXD1;
AT91C_BASE_PIOB->PIO_BSR = 0;
AT91C_BASE_PIOB->PIO_PDR = AT91C_PB6_TXD1 | AT91C_PB7_RXD1;
/* === Configure serial link === */
/* Define the baud rate divisor register [BRGR = MCK / (BAUD RATE * 16)] */
AT91C_BASE_US1->US_BRGR = 7; //27 for 230400 ## 54 for 115200 ## 108 for 57600 ## 647 for 9600 ## 1293 for 4800 ##7 for 921600
/* Define the USART mode */
AT91C_BASE_US1->US_MR = AT91C_US_PAR_NONE
| AT91C_US_USMODE_NORMAL
| AT91C_US_CLKS_CLOCK
| AT91C_US_CHRL_8_BITS
| AT91C_US_NBSTOP_1_BIT
| AT91C_US_CHMODE_NORMAL;
/* Enable transmitter */ //and receiver :)
AT91C_BASE_US1->US_CR = AT91C_US_TXEN;
AT91C_BASE_US1->US_CR = AT91C_US_RXEN;
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_US1; //providing clock from the PMC
AT91C_BASE_PIOB->PIO_PPUER = AT91C_PB6_TXD1;
}