Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

RS232 coding problem

Altera_Forum
Honored Contributor II
1,145 Views

Hi all, 

 

I require to send/receive a character through the rs232 port, however i only be able to receive character. I had problem with sending the character out. Below is my coding for sending and receiving. Please kindly provide me with advise/solution. Thanks 

 

 

void serial() 

int a = 99; 

char c; 

c=IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE); 

printf("%c",c); // result shown is correct 

 

IOWR_ALTERA_AVALON_UART_CONTROL(UART_0_BASE, 0x40); 

IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE,a);//NO CHARACTER DETECTED  

 

}
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
380 Views

hello, I have made similar program. 

I don't remember exactly what I did. 

the code was  

------------------------------------------------------------------- 

 

void putUchar(unsigned char str) 

IOWR_32DIRECT(H55UART_BASE,OFF_TXDATA ,str); 

usleep(UART_WAIT); // UART_WAIT is 1000 

------------------------------------------------------------------- 

 

I think 1msec wait ( for 9600bps) is what you need. 

how is it?
0 Kudos
Altera_Forum
Honored Contributor II
380 Views

Hi Akira, 

 

I had try to add on the usleep(1000) below my code, but yet no character is detect in my VB(visual basic) where I use to detect and send character. But anyhow, thanks for your advice.
0 Kudos
Altera_Forum
Honored Contributor II
380 Views

how about doubting VB. 

 

in some case you can not get characters when the character is not correct ASCII code. 

you should measure the signal TX. by oscilloscope or signaltapII. 

 

or, just send UART signal from NiosII to "the NiosII" by itself. 

 

good luck.
0 Kudos
Altera_Forum
Honored Contributor II
380 Views

The easiest terminal emulator to use on windows (and probably linux) is putty. Testing with that will remove some of the unknowns.

0 Kudos
Altera_Forum
Honored Contributor II
380 Views

thanks.... putty really save me out. Now i know is my VB problem.

0 Kudos
Altera_Forum
Honored Contributor II
380 Views

hi vincoldes! 

i'm trying to finish my graduation project, for that i need to receive some text in my DE2 rs232 port and i'm using nios ii like u, i was wondering if you can help me here sending me your code? sorry but i'm really desperate =( 

 

hope to hear soon from you =)
0 Kudos
Altera_Forum
Honored Contributor II
380 Views

Hi liscabello, 

 

I found that we have 2 ways of doing it: 

 

1. Using simple getc(fp) function where by pointer *fp is point to my uart. The code is something like this:  

 

FILE *fp 

fp = fopen ("/dev/uart_0", "r+"); 

while(fp) 

 

getc(fp);read 

 

 

fclose(fp) 

 

2. Using IORD & IOWR for read and write.Example code as below: 

 

IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE,*(b+j)); for write 

IORD_ALTERA_AVALON_UART_TXDATA(UART_0_BASE,*(b+j)); for wirte 

 

You can refer to the handbook for further details. Sry that if I cant help much:)
0 Kudos
Altera_Forum
Honored Contributor II
380 Views

thank u vincoldes :) i'll try this as soon as i get home

0 Kudos
Reply