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++

UART wierdness

Altera_Forum
Honored Contributor II
1,731 Views

I'm trying to interface with a cell phone to the DE2 board over serial. I've been able to successfully talk to the phone using my computer and an FTDI cable. I know the baud and all of the other settings are correct. The phone has an Rx, Tx, and ground (it doesn't have every pin that a real serial port does). I added the UART module in the SOPC editor and found some example code in the Altera documentation. It all compiles. I connected my computer to the DE2 serial port with the FTDI cable and was able to send characters over. However, the characters that arrive are a garbled version of what I sent. It's very weird. But I took that to mean that at least the serial connection was working (to a degree). So in summary, I can receive stuff with the DE2 (albeit corrupted), but I can't get it to send anything at all. I really don't care if I can send data to the DE2, I just care about sending data from it to the phone. Does anyone have any theories as to what could be happening? If it would help, I can provide some output or screenshots or something. 

Thanks.
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
428 Views

Here's some more information that might be helpful: 

Here's what my setup looked like: 

img14.imageshack.us/img14/9618/context.png 

 

 

This screenshot shows in the console what output I got when I send the word "test" in ascii across serial from my laptop. The code above it is the section that is all the serial connection related stuff: 

img140.imageshack.us/img140/7619/screenshot1lj.png 

 

(A couple quick notes about that code: I try several different ways of sending data, and I know for a fact that I need the \r\n end of line characters for the phone to recognize what's being sent). 

 

And here's what the DE2 sees when I send a valid command to the phone. I sent "ATD +17274203684;" in ascii, which is the command to place a call. The phone sent back a response which I saw on my laptop, and it also made the call. However, the DE2 was also listening in on that connection and saw this:  

img140.imageshack.us/img140/7619/screenshot2mx.png 

 

 

So clearly, the problem is with the DE2. As far as hardware, my only theory is that maybe it is expecting some data from the other pins that aren't being used on the serial port. Like I said, I'm only using Rx, Tx, and GND, and there are 6 others that aren't necessary (my computer is communicating fine without them) but the DE2 might want. If the problem isn't with hardware, then it must be my code. And I still haven't gotten the DE2 to send anything at all. 

 

Any thoughts? I need to get this working by 4/27, so anything at all would be appreciated.
0 Kudos
Altera_Forum
Honored Contributor II
428 Views

I can't see the images you posted; there's is some error with the attachments. 

Anyway, usually when you receive weird characters on a uart serial port, you have a problem with the baudrate. i.e.: xmitter and receiver are not set at the same baudrate and char codes are interpreted in a wrong way.  

Possibile causes of problem: 

- code: you did set a wrong baudrate on xmitter or receiver 

- hw: clock problem; the nominal baudrate is correct but the actual one is not, so you get data rate mismatch on the serial line; you can simply check with an oscilloscope 

- code or hw: a problem in character decoding; debug the uart interface and the sw driver 

- phy: noise on the serial line link 

 

 

--- Quote Start ---  

As far as hardware, my only theory is that maybe it is expecting some data from the other pins that aren't being used on the serial port. Like I said, I'm only using Rx, Tx, and GND, and there are 6 others that aren't necessary (my computer is communicating fine without them) but the DE2 might want.  

--- Quote End ---  

 

 

The other pins are ininfluent; they are only used for flow control. If you can actually send and receive data (although weird it is), then the problem is not with these pins. 

 

Regards 

Cris
0 Kudos
Altera_Forum
Honored Contributor II
428 Views

I can now see the first two images. The first one shows a bad connection, if I interpreted it correctly. 

If you are using a RS232 cable, you can't make a star connection: only point to point is allowed, otherwise you'd have two transmitters driving the same line. 

I think this is your problem.
0 Kudos
Altera_Forum
Honored Contributor II
428 Views

Thanks for your reply. I realized the problem with trying to connect all 3 things, and stopped doing that. I tried connecting the phone directly to the serial port on the DE2. I was able to get the Tx LED on the DE2 to light up for a second when my code sent stuff, so I think it is at least transmitting. I tried connecting the serial port on the DE2 to my computer via the FTDI cable and didn't receive anything. I know the DE2 is at least executing my code to send data, and based on the Tx LED, it is making it to the serial port, but after that I don't know what happens. Tonight I'm going to hook up a logic analyzer to the Tx coming from the DE2 to see what the data actually looks like and if it is really transmitting. I'll post my findings and hopefully it'll be helpful.

0 Kudos
Altera_Forum
Honored Contributor II
428 Views

I'm in the lab right now and after hooking up the o-scope and the logic analyzer, I am getting nothing from the serial port on the DE2. The Tx light blinks, but nothing is triggering and even the signal on the scope doesn't look jittery or anything when the Tx light is on. I tried changing the sensitivity levels on everything to watch for something larger than TTL, but still nothing. I will be in the lab till 12am Eastern time, so I can try things out immediately until then. I'm pretty stuck at this point. Here's what I'm using now try to send stuff over serial: 

 

void test8_uart(void){ int uart, result; char szHello = "\r\nAT+++\r\n"; //this 'wakes up' the phone to receive commands char szHello2 ="ATD+15551234;\r\n"; //this is the actual command char szRead; //open uart uart = open(UART_NAME, O_ACCMODE); //defined in system.h if(!uart){ printf("failed to open uart\n"); return; } //write uart if(write(uart, szHello, strlen(szHello)) == strlen(szHello)){ printf("wrote message 1 to uart\n"); usleep(1000000); } if(write(uart, szHello2, strlen(szHello2)) == strlen(szHello2)){ printf("wrote message 2 to uart\n"); } close(uart); return; }  

 

The only thing I can think of is that I configured something wrong in the SOPC editor. It's almost like the lines going from the FPGA aren't connected to the physical serial port. Here's what my SOPC config looks like: 

img9.imageshack.us/img9/4353/sopc.png 

 

Is there anything in there that I am missing that is needed to make the uart work? Or should I use a different uart module? I can add: 

Avalon-ST JTAG Interface 

Avalon-ST Serial Peripheral Interface (SPI) 

JTAG UART 

SPI (3 wire serial) 

UART (RS232 serial port) [this is the one I'm using now] 

or since we have the University Program, I can also add  

RS232 UART 

 

 

I will be eternally grateful for your help :)
0 Kudos
Altera_Forum
Honored Contributor II
428 Views

The UART module you selected in sopc is right. 

The connection in sopc is right, too. 

I can't check right now, but I think you can make some settings in the uart module, before generating the system (flow control, interrupt, ...): did you verify everything is correct? 

After sopc generation you should see the uart pins (at least rx and tx) on the sopc symbol you include in Quartus. Are you sure these signals have been correctly connected and routed to the right fpga pins, I mean the pins physically connected to the DE2 serial port? 

 

Regarding the signal levels, if you are using RS232, you don't have TTL, but bipolar levels: 

high level : +5V to +15V 

low level: -5V to -15V 

(the actual absolute voltage depending from the driver) 

 

I can't give you advice on the software code, since I never used the uart; so I don't know if your open() call is enough to init and start the serial port 

 

Cris
0 Kudos
Altera_Forum
Honored Contributor II
428 Views

I found the problem. It turns out that I was using the male pinout and I should have been using the female one. Basically the top row of pins goes 5-1 instead of 1-5. Doh!

0 Kudos
Altera_Forum
Honored Contributor II
428 Views

Hello I'm new here and I now the post expired a long time ago, but i´m working with the same board DE2 and a module gsm sim340cz, i want send a message through the DE2 to my cell phone but i don´t know how exactly is in Nios II code in C, because I'm connecting all together but the message is no send, even i have my code and I use the Expansion Headers JP1 and i adding my uart in those pins 

please anyone can healp me, thank a lot
0 Kudos
Reply