Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

uart interrupt program

i debug this program in standard UART,and it run corectly.but when i used this program in my expanded UART,this program isn't go well, it can't receive data.

i checked my hardware and it goes well, i think it is the interrupt's problem.

my program is here ,please help me,i did this for a week.

/*used in testing uart1 txd and rxd*/# include <stdio.h># include <string.h># include <unistd.h># include "system.h"# include "sys/alt_irq.h"# include "altera_avalon_uart_regs.h"# include "alt_types.h"# include "altera_avalon_pio_regs.h"

# define rxbufsize 10 # define rxdatasize 3

unsigned char rxbuf[rxbufsize];

long int rxhead=0;

long int rxtail=0;

void simplereceive1(void *context,alt_u32 id);

unsigned char _getchar();

int main(void)

{

void* context;

int i=0;

unsigned char rxdata[rxdatasize];

//int led=0x01;

printf("Simple\n");

alt_irq_register(UART1_IRQ,context,simplereceive1);//&#27880;&#20876;&#20013;&#26029;

IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE,ALTERA_AVALON_UART_CONTROL_RRDY_MSK);//&#20351;&#33021;&#20018;&#21475;&#25509;&#25910;&#20013;&#26029;

while(1)

{

usleep(15000);

i=0;

while(rxtail!=rxhead)

{

rxdata=_getchar();

iowr_altera_avalon_uart_txdata(uart1_base, rxdata);

i++;

}

/*if (i==rxdatasize && rxdata[0]==&#39;a&#39; && rxdata[1]==&#39;b&#39; && rxdata[2]==&#39;c&#39;)

IOWR_ALTERA_AVALON_PIO_DATA(LED_GREEN_BASE,led);

else

led=0;

IOWR_ALTERA_AVALON_PIO_DATA(LED_GREEN_BASE,led);*/

}

}

void simplereceive1(void *context,alt_u32 id)//uart ISR

{

rxbuf[rxhead]=IORD_ALTERA_AVALON_UART_RXDATA(UART1_BASE);/*&#20018;&#21475;&#25509;

&#25910;&#21040;&#26032;&#25968;&#25454;&#65292;&#23558;&#20854;&#25918;&#20837;&#25509;&#25910;&#32531;&#20914;&#21306;&#25968;&#25454;&#27969;&#23614;*/

if ((++rxhead)>(rxbufsize-1)) rxhead=0;/*&#22914;&#26524;rxhead&#32034;&#24341;&#20540;&#24050;&#21040;&#25968;&#32452;

&#26411;&#23614;&#65292;&#36820;&#22238;&#25968;&#32452;&#22836;&#37096;*/

IOWR_ALTERA_AVALON_UART_STATUS(UART1_BASE, 0);//&#20018;&#21475;&#29366;&#24577;&#23492;&#23384;&#22120;&#28165;&#38646;

}

unsigned char _getchar() //&#33719;&#21462;&#25968;&#25454;&#30340;&#20989;&#25968;

{

unsigned char ret;

ret=rxbuf[rxtail];

if (++rxtail>(rxbufsize-1)) rxtail=0;

return(ret);

}
No RepliesBe the first to reply