- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi
if somebody want to try uart device , i post a simple code that's running of course it's not complete but i would like to start a common little project with all people write in this community . # include "count_binary.h" int val; int uart_0; char buf[255]; alt_u8 counter; // REGISTER static void handle_uart_interrupt(void* context,alt_u32 id) { val++; //everytime i receive a caracter increment and display on leds Write_Output(val); //using this macro automatically bit ready to receive will be resetted //and ready for a new interrupt when shifter register finish to translate last bit //in the uart device buf[counter]=IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE) ; counter++; if (counter==6) {printf("riceived:%s\r ",buf); counter=0; } } static void Write_Output(alt_u8 val) { IOWR_ALTERA_AVALON_PIO_DATA(PM_OUT_BASE, val); } int main(void) { int i; volatile int uart_0; val=0; while( 1 ) { IOWR_ALTERA_AVALON_UART_CONTROL(UART_0_BASE, 0x180); alt_irq_register(UART_0_IRQ,&uart_0,handle_uart_interrupt); } return(0); } i use vc#.net to send a string ("walter") of 6 caracters . In Nios II ide console is displaying as follows received:walter i think this sample will be good for many people want to start to use uart device and interrupt . I stay 2 days reading and trying to gain this , i'm not clever . Of course need to implement also transmit interrupt and create a protocol but if other people contribute to continue it's possible to obtain very interesting development ciao walterLink Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it's uncredible how the world is absent
and how everybody anly ask and want http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/blink.gif- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- originally posted by pmicro@Mar 22 2006, 02:02 PM it's uncredible how the world is absent
and how everybody anly ask and want
http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/blink.gif
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=13692)
--- quote end ---
--- Quote End --- this is the code i do rs232 interrupt... no hard feeling.. everyone is bz see how easily i can use the rs232 wth PIC uC... no need clear or set any flag, all is done by compiler (CCS C).. i dunno how u do in nios C
//date: 07/01/2006
//function: use PC to send 4 character to PIC and when the 4 character is detected as "ABCD" (ASCII), it echo back.
// : the "ABCD" sequence have to be correct or it will not echo back to PC.
# include <16F877A.h># fuses HS, NOWDT, NOPUT, NODEBUG, NOLVP, NOBROWNOUT, NOCPD, NOPROTECT, NOWRT# use delay(clock = 20000000)
# use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
# INT_RDA //RS232 receive data available
void isr_rs232(){
int A_char, B_char, C_char, D_char;
int protocol; // use as a dummy to make sure the sequence of character received is correct.
A_char = getc();
if (A_char == 'A'){
protocol = 1;
}
if (protocol == 1){
B_char = getc();
if (B_char == '3'){
protocol = 2;
}
}
if (protocol == 2){
C_char = getc();
if (C_char == 'C'){
protocol = 3;
}
}
if (protocol == 3){
D_char = getc();
if (D_char == 'D'){
protocol = 4;
}
}
if (protocol == 4){
putc(A_char); putc(B_char); putc(C_char); putc(D_char); //echo back the character u send to your PIC
}
protocol = 0; //clear the dummy for further use.
}
void main(){
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
while(1){
; //do nothing and wait for rs232 interrupt
}
}
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