Hi,
But the current device I'm tinkering with is a custom UART.
I think there are two conventional approaches to receive data from that.
One approach is through Interruption by registering the
device with a ISR,and when a char comes in,the program
would automatically jump into the receiver ISR and operate
the code just received.
The other alternative is requiring the relevent register(or checking the state),
such as RRDY in the status register.
But now, though both of the approaches I have tried,
the UART device cannot receive any char,I really cannot figure out why.
1)The code for the first approach is like this :
------------
(the code in main)
alt_irq_register(GSM_UART_IRQ, (void*) &context, gsm_rxd);
IOWR_ALTERA_AVALON_UART_CONTROL(GSM_UART_BASE, ALTERA_AVALON_UART_STATUS_RRDY_MSK);
------------
and
------------
(the receiver ISR)
void gsm_rxd(void* context, alt_u32 id)
{
rxbuffer[rxhead]= IORD(GSM_UART_BASE,0);
IOWR_ALTERA_AVALON_UART_STATUS(GSM_UART_BASE, 0);
printf("The char received are %c\n",rxbuffer[rxhead]);
if( (++rxhead) > (SIZE-1) )
rxhead=1;
}
------------
2)And the code for the second approach is like following:
------------
void gsm_rxd()
{
while((IORD(GSM_UART_BASE,2)&0x80)!=0x80)
;
rxbuffer[rxhead]= IORD(GSM_UART_BASE,0);
printf("\nThe order received i
s:\n");
//printf("%x",IORD(GSM_UART_BASE,0));
printf("%x",rxbuffer[rxhead]);
IOWR_ALTERA_AVALON_UART_STATUS(GSM_UART_BASE, 0);
if( (++rxhead) > (SIZE-1) )
rxhead=1;
}
-------------
Please help me to figure out why the two type of routines
just do not work.
http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/huh.gif
Besides, the transmitting routine I wrote is like this:
--------------
void gsm_txd(char data[],char length)
{
volatile char m;
printf("\nThe command sent i
s:\n");
for(m=0;m<length;m++)
{
while((IORD(GSM_UART_BASE,2)&0x40)!=0x40)
;
IOWR(GSM_UART_BASE,1,data[m]);
printf("%c",IORD(GSM_UART_BASE,1));
}
}
Because it works so fine when it operates, so I
made a receiving routine following the pattern of the
transmitting routine, which is the code 2) I just wrote above.
So the second question is why this receiver
function do not work as its counterpart as a
transimitter routine?
Thank you for your suggestions and helps...
http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/wink.gif
Regards,
Don