- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
I am trying to use the rs232 interrupt. sending and receiving data works fine, but when i try to use the interrupt to receive data I get some problems. this is the rs232 block in my system.h /* * uart_rs232 configuration * */ # define UART_RS232_NAME "/dev/uart_rs232" # define UART_RS232_TYPE "altera_avalon_uart" # define UART_RS232_BASE 0x0a201280 # define UART_RS232_SPAN 32 # define UART_RS232_IRQ 18 # define UART_RS232_IRQ_INTERRUPT_CONTROLLER_ID 0 # define UART_RS232_BAUD 9600 # define UART_RS232_DATA_BITS 8 # define UART_RS232_FIXED_BAUD 0 # define UART_RS232_PARITY 'N' # define UART_RS232_STOP_BITS 1 # define UART_RS232_SYNC_REG_DEPTH 2 # define UART_RS232_USE_CTS_RTS 0 # define UART_RS232_USE_EOP_REGISTER 0 # define UART_RS232_SIM_TRUE_BAUD 0 # define UART_RS232_SIM_CHAR_STREAM "" # define UART_RS232_RELATIVEPATH 0 # define UART_RS232_FREQ 100000000 # define ALT_MODULE_CLASS_uart_rs232 altera_avalon_uart //this is my context typedef struct { int number; }my_context; //This is my ISR void rs232_isr (void* context, alt_u32 interrupt_number) { printf("data gets in"); } //this I call in my main at first void main(){ char msg[4]="test"; int result; result=alt_irq_register (UART_RS232_IRQ, (void*)my_contex, rs232_isr); alt_irq_enable(UART_RS232_IRQ); do{ fp = fopen("/dev/uart_rs232", "w+"); if(fp) { //printf("Connected\n"); fwrite(msg, strlen(msg), 1, fp); //fprintf(fp, "Closing the UART file.\n"); fclose(fp); } else { printf("Error/dev/ttyS0\n"); } }while(1); } If I start the my program the rs232_isr is called I think one hundred times... I think the rs232_isr is called by the fwrite(..). Is there a method to recognize only the RXD without react everytime at TXD (text send).Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nobody who van help me?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
check this thread.
http://www.alteraforum.com/forum/showthread.php?t=13134 It contains also some code samples how to do it.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I red the other thread and now my isr works, but now the write function does not work..nothing is send, only the RXD comes
volatile int counter; init RXD /* flush any characters sitting in the holding register */ IORD(UART_RS232_BASE, 0); IORD(UART_RS232_BASE, 0); /* reset most of the status register bits */ IOWR(UART_RS232_BASE, 2, 0x00); /* install IRQ service routine */ alt_irq_register(UART_RS232_IRQ, 0, serial_irq_0); /* enable irq for Rx. */ IOWR(UART_RS232_BASE, 3, 0x0080); The ISR is so: static void serial_irq_0(void* context , alt_u32 id) { unsigned int stat,temp; int chr[3]; // message[0]=getc(fp_read); /* get serial status */ stat = IORD(UART_RS232_BASE, 2); /* character Rx */ if (stat & 0x0080) { message [counter]= IORD(UART_RS232_BASE, 0); } if(counter==2){ printf("char: %c%c%c",message[0],message[1],message[2]); counter=0; } else counter++; } In a Task I wrote this to write: FILE *fp_write; fp_write = fopen("/dev/uart_rs232", "w+"); //also used r+ if(fp_write) { //printf("Verbunden\n"); fwrite(pic_viewer->message, strlen(pic_viewer->message), 1, fp_write); OSTimeDlyHMSM(0, 0, 0, (20)); //fwrite(msg,strlen(msg),1,fp); //sprintf(msg,"%i",400); //fwrite(msg, strlen(msg),1,fp); //fprintf(fp, "Closing the UART file.\n"); fclose(fp_write); sprintf(pic_viewer->message,"%s","00050200"); } else { printf("Error/dev/ttyS0\n"); }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am not really sure about your code.
I would guess message[] is a receive buffer but ... Are you using a mix of standard lib and your own code on the same RS232? I strictly separated then and have no trouble.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page