ve3id
Posts: 13
Joined: Fri Sep 20, 2013 3:39 pm

Modem using USB serial I/O

Tue Nov 26, 2013 11:21 pm

I have an app that I wrote in gcc that reads caller ID strings from a Trendnet TFM560X modem. It compares them to a list of valid numbers and triggers a parallel port bit when a match is found. It does not answer the phone.

I have fully debugged the program and the modem on an old Compaq Presario desktop running SuSE 11.1 using the built-in serial port /dev/ttyS0.

I moved the app to a raspberry pi model B, running debian 7.1, changed the code to use /dev/ttyUSB0 and re-compiled.

I tested it on my bench using a null modem attached to a serial dongle on my development PC sending logged caller ID strings from the same modem and that was fine too.

Then I installed it on a second phone line in a remote room and connected it to a modem. Thence it worketh not!

So, in troubleshooting, I ran minicom on the pi and can see the modem sending the word "RING", but no caller ID strings. I checked the phone line using a regular phone and it is getting good caller ID. I can command to dial out and make my cell ring from it. I am initialising the modem with at+vcid=1 which enables caller ID and has worked in my other setup.

I have also tried changing line settings using stty to everything I can think off, setting clocal, cmodem, cread etc. I would believe that I am having a modem control or handshaking problem except that I can see the word "RING" coming through!

Originally, I did have a problem using the serial dongle, it would take too much current and the pi would reset when I plugged it in. Then I bought the adafruit 1Amp USB power supply and it does not crash, but gives the above results.

I have read many posts in various fora, some of which talk about driver issues, but nothing seems to be symptomatic of my problem.

Does anybody have any ideas of other things I can check?

This is spoiling my first project with a pi!

cheers,
Nigel Johnson
ve3id

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Modem using USB serial I/O

Wed Nov 27, 2013 12:34 am

Hi Nigel,
ve3id wrote:So, in troubleshooting, I ran minicom on the pi and can see the modem sending the word "RING", but no caller ID strings.
This your problem reminded me about one I faced in the past with one crappy serial dongle. It worked well untill burst of data has ocurred. So, everything worked well during manual typing, but during "real world" data packet transmission, internal buffer overflow ocurred in the dongle and some data was lost.

To verify that the dongle works ok, connect it to the PC instead or RasPi and check what is the received data content...


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

ve3id
Posts: 13
Joined: Fri Sep 20, 2013 3:39 pm

Re: Modem using USB serial I/O

Wed Nov 27, 2013 1:38 am

Thanks for the suggestion. It certainly raises a possibility. Only problem is, why would it work when I tested it on the bench? I will go down tomorrow (it is mounted in a ceiling electrical box in a mechanical room) and try to get my laptop hooked into it, as well as swapping the serial dongle with another brand.
Thanks,
NIgel

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Modem using USB serial I/O

Wed Nov 27, 2013 2:07 am

Hi Nigel,
ve3id wrote:Only problem is, why would it work when I tested it on the bench?
I understood that your testing was with null modem cable between PC (internal RS-232) and RasPi (this dongle)... therefore, next to a "different micro location" ;-) the hardware was also not exactly the same.
Modems and other dedicated boxes contain optimized communication routines and priorities (alias throughput). On the other hand, I'm also not sure what's inside your PC - not all of them have UART chips with 16-bytes buffers, so there could always be a time gap between each character sent.

Additionally, since the serial port speed is not important for you at all, you migh also check if problem remains at lower speeds (eg. 2400bps). You also didn't mention what are flow control settings. Set them to hardware and make sure that you're using proper cable...


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

ve3id
Posts: 13
Joined: Fri Sep 20, 2013 3:39 pm

Re: Modem using USB serial I/O

Sun Dec 01, 2013 3:21 pm

Thanks for all your feedback. It seems that this is a problem with the USB driver in the raspberry pi that has been mentioned in other fora. If I hook my laptop to the modem I get all the correct data.

I still can't figure out why it works on the test bench though!

For the time being, unless I can find some patch to the driver to fix the problem, I will simply just buy a 3.3V to RS232 converter for /dev/AMA0 and use that to talk to the modem.

cheers,
Nigel

ve3id
Posts: 13
Joined: Fri Sep 20, 2013 3:39 pm

Re: Modem using USB serial I/O

Mon Dec 02, 2013 2:20 pm

Well, converting the console 3.3 to RS232 didn't work either.

I can see a correct response from the modem every time using another computer, but now I have it hooked up to the console of the pi I am still getting the word "RING" when I call the modem but absolutely no caller-id strings in formatted mode, and different length strings when I tell it to give me raw mode and call from the same phone number..

I have tried all sorts of stty options such as raw and clocal, as well as hard wiring dtr on the modem.

This is driving me silly! It seems like there is some path inside the pi that is losing characters and that is common between the USB controller and the console serial port. Seems to be pattern sensitive.

Anybody got any ideas?

cheers
Nigel

MattF
Posts: 55
Joined: Tue Feb 12, 2013 10:01 am

Re: Modem using USB serial I/O

Tue Dec 03, 2013 12:02 am

Long shot, but just in case you are sending AT+V1E1 as part of the init string?

Also check if there is a ttyUSB1 sometimes one gets rather more serial ports than anticipated and different results on different ports (data/control on 0, control only on 1)

Check usb_modeswitch is fully up to date as well.

ve3id
Posts: 13
Joined: Fri Sep 20, 2013 3:39 pm

Re: Modem using USB serial I/O

Tue Dec 03, 2013 1:11 am

I am not familiar with AT+V1E1, what is it supposed to do? Anyway, the modem does not accept it, gives error message.

Other comments about USB are moot at this point, I have given up on using USB serial dongles and am using the console /dev/ttyAMA0 with a voltage converter to get the RS232 levels of the modem.

So to recap, I am seeing all the correct responses if I hook my laptop to the modem , but only RING and OK when I use the pi running minicom, kermit, or my own program talking to AMA0, at any baud rate from 300 baud to 115200!.

Added 20131202 2140 EST(UTC-5): I have just tried talking to the modem using ser2net, and get absolutely the same results. It seems like any time a response is more than 4 characters it eats the whole response, not even getting garbage strings out.

cheers,
Nigel
Last edited by ve3id on Tue Dec 03, 2013 2:41 am, edited 1 time in total.

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Modem using USB serial I/O

Tue Dec 03, 2013 2:32 am

Hi Nigel,
ve3id wrote:So to recap, I am seeing all the correct responses if I hook my laptop to the modem , but only RING and OK when I use the pi running minicom, kermit, or my own program talking to AMA0, at any baud rate from 300 baud to 115200!
Weird... :-/

Type "AT&V0". This command returns a bit longer response. Maybe you can find a pattern (of lost characters) when comparing received data on laptop and RasPi.

Additionally, can you set two stop bits on modem (just on modem!) ? This setting would insert additional bit time "pause" after each character sent.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Modem using USB serial I/O

Tue Dec 03, 2013 2:35 am

ve3id wrote: So to recap, I am seeing all the correct responses if I hook my laptop to the modem , but only RING and OK when I use the pi running minicom, kermit, or my own program talking to AMA0, at any baud rate from 300 baud to 115200!.
cheers,
Nigel
I doubt it's the Pi at all.

Is this the *same* modem in the *same* location on the *same* phone line?

You mentioned that you installed a second phone line. Did you ask the phone company to turn on the Caller ID feature on the second line?

Is it a handshaking thing? Does the modem expect DTR or some other signal to be asserted?

ve3id
Posts: 13
Joined: Fri Sep 20, 2013 3:39 pm

Re: Modem using USB serial I/O

Tue Dec 03, 2013 3:05 am

To Ivan:

AT&V0 gives three pages of beautiful text, not an obvious missing or garbled character! From that I see the modem is set to ignore DTR, flow control is disabled, .Results are set to text and extended results are enabled.

I tried at+icf=1to set 2 stop bits, but the modem does not recognise this code. Do you know another way to force it to send using 2 stop bits?

To ame:

Yes I have 2 phone lines and 2 modems, have checked the second line for caller ID successfully with a regular phone and it works. It must be the pi, because if I hook my SuSE linux laptop to the modem using a serial USB dongle I get all the correct responses from the modem. Everything works fine until I use the pi, with either the console serial port or a USB serial dongle

Perhaps it is the software? I am more familiar with SuSE and I see they have a dis for the pi now, maybe I will try that next.

I was a field engineer for 20 years before I started teaching college, and this beats me!

cheers,
Nigel

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Modem using USB serial I/O

Tue Dec 03, 2013 3:24 am

ve3id wrote: Yes I have 2 phone lines and 2 modems, have checked the second line for caller ID successfully with a regular phone and it works.
Have you checked the second line with the second modem and the linux laptop?

Have you checked the first line with the first modem and the Pi?

ve3id
Posts: 13
Joined: Fri Sep 20, 2013 3:39 pm

Re: Modem using USB serial I/O

Tue Dec 03, 2013 12:31 pm

Both lines work fine with both modems and the laptop.

The second line (which is giving the trouble) fails to receive anything more than RING and OK on an incoming call when I run standard terminal programs like minicom, screen, kermit, and also ser2net. I will test the first line with the pi tonight!

thanks for your consideration

Nigel

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Modem using USB serial I/O

Tue Dec 03, 2013 9:34 pm

Nigel,
ve3id wrote:I tried at+icf=1to set 2 stop bits, but the modem does not recognise this code. Do you know another way to force it to send using 2 stop bits?
Unfortunately not.
According to your answer about complete "AT&V0" response, I have doubts that characters got lost...

For debugging purposes, try to use the same "hardware" and "software" with laptop and RasPi as much as possible, including serial cable.
Do you use any modem init strings in apps/scripts ? You could set configuration once and then save it (AT&W). Afterwards, just load this stored configuration (ATZ) from any code used. Thus, you cannot overlook some init differences during troubleshooting with various apps.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Modem using USB serial I/O

Wed Dec 04, 2013 12:45 am

ve3id wrote:Both lines work fine with both modems and the laptop.

The second line (which is giving the trouble) fails to receive anything more than RING and OK on an incoming call when I run standard terminal programs like minicom, screen, kermit, and also ser2net. I will test the first line with the pi tonight!

thanks for your consideration

Nigel
Well it's a conundrum. Given the description of the situation I strongly suspect that it is *not* that the Pi is not *receiving* the caller-ID data, but rather that the modem is not *sending* caller-ID, although I don't know why. Either there's a hardware override, or the modem didn't actually receive the instruction to send caller-ID.

I suspect two things.

1) The serial port control lines
If you are using the Pi console port then there are no control lines (DTR, RTS etc.). How about making a wiring adapter for the laptop that connects only TxD, RxD and GND straight through, and try running the software on the laptop again.

2) Buffer overflow
Can you delay the commands sent by the Pi to configure the modem so that there is an inter-character delay, or a delay between AT strings? Is there a typo in the command string?

If you have a storage oscilloscope you could capture the bitstream sent by the laptop and compare it to the Pi (but not many people do).

How about using the laptop to configure the modem and then plugging the Pi into the modem? The laptop configures the modem and the configuration should persist.

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Modem using USB serial I/O

Wed Dec 04, 2013 1:00 am

Hi,
ame wrote:If you have a storage oscilloscope you could capture the bitstream sent by the laptop and compare it to the Pi
He could use laptop to capture data received by RasPi. ;-)

No, I'm not joking. Seriously... he could make Y cable - solder additional DB9 connector with just two connected pins: GND and Rx pin (receive signal from RasPi perspective)... If received streams on laptop and RasPi are equal, then we can exclude RasPi as a source of the issue.
(Equally, when laptop receives complete data, then RasPi can be also connected as sniffer to this new connector...)

Important: To be deeply on the safe side, laptop should work on batteries during this procedure.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

ve3id
Posts: 13
Joined: Fri Sep 20, 2013 3:39 pm

Re: Modem using USB serial I/O

Wed Dec 04, 2013 12:21 pm

Thanks for the good pointers. I think the Y adapter and using the laptop as a monitor is very practical and I will try it next. I do have a logic analyser but unfortunately it works with 5V logic levels only, such is the pace of technology :-(

And I will make theY adapter only three wires to eliminate the possibility that it is modem control, but using the original USB-serial adapter would have given me modem control anyway.

The other thing that comes to mind is that the first word of the caller id output is "DATE", I wonder if the pi is actually accepting this as a linux command even though I have edited /etc/inittab and /boot/cmdline.txt to take it out? I have noticed that sometimes the word "RING" also gets lost but later ones do appear, as if the pi is going off to think about it.

By the way, I have passed this around the office (I teach college) and other engineers and technologists are eagerly awaiting the solution because we are all stumped!

I will report back.

cheers,
Nigel

obcd
Posts: 917
Joined: Sun Jul 29, 2012 9:06 pm

Re: Modem using USB serial I/O

Wed Dec 04, 2013 3:49 pm

RING
sounds like the normal string a hayes compatible modem is sending on an incoming call.
I would expect the modem to need some init commands or some handshake line set before it will send the caller id information when a call comes in.

Using the Y cable might make you wiser.

You could connect the modem to the laptop first, and to the Pi afterwards without powering down. Every initialisation commands will remain present in the modem, unless it get's a factory reset command from the Pi.

The ttyama0 pi port has a glitch. It might send a bogus character to the modem during powerup.
Maybe the modem will wait for an additional "carriage return" before it will consider the connection idle and send it's data. This could explain a missing "RING"

Other things that could influence the communication is the sending of an <XOFF>. The modem might wait for an <XON> before it sends it's data.

ve3id
Posts: 13
Joined: Fri Sep 20, 2013 3:39 pm

Re: Modem using USB serial I/O - SOLVED

Wed Dec 04, 2013 9:09 pm

Well, getting down to the nitty-gritty in troubleshooting I made up a cable to monitor the outgoing and return data to the modem on two separate USB dongles on my laptop. Despite someone's advice to the contrary, I forgot to unplug my laptop and left it connected to a grounded (earthed in English :-) ) outlet.

Lo and behold, everything started working! Pull put the USB cables to the laptop, everything stops!

Seems like the problem was the ground wire from the modem to the pi was, for some strange reason, not good enough. I grounded pin 5 of the serial cable to an electrical box and removed my test cables, and so far everything is working.

I guess the problem lies in the fact that the modem does not pick up a ground through its double-wound transformer, and pin 5 does not connect to anything important!.

Weird problem now solved, and thanks to all those who scratched their heads with me on this one.

cheers,

Nigel

Return to “Troubleshooting”