Xbee interface

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
meenbombs
Posts: 35
Joined: 20 November 2008, 15:54 PM

Xbee interface

Post by meenbombs »

I am attempting to interface my ZX-328n with my Xbee through com3. I can successfully send the date from the ZX to the Xbee and read it with a remote Xbee. However, I am not so lucky the other way around. When I send data (like the number 5) from the Xbee to the ZX I just a lot of gibberish if the variable I am filling from the queue is a string. If I fill a byte variable from the queue I just get the numbers 128 and 248.

I suspect I have some sort of data conversion error. But here are my connections in the event that is the problem.

Xbee TX (pin 2) to ZX pin 6. The Xbee holds it at 3.25 volts until it is transmitting and then it fluctuates a few tenths of a volt lower (I only have a $20 meter and no scope)

I have no trouble with data in the other direction but I am just outputting the ZX through a divider circuit using two resistors to get it below the 3.3V the Xbee requires.

All of this is occurring with the two devices separated by about 6 inches of wire. Thanks in advance.

Code: Select all

Const crlf as String = Chr(&H0d) 
Const comPort as Byte = 3 
Const rxPin as Byte = 6 
Const txPin as Byte = 4 
Const qsize as Byte = 40 
Dim oq(1 to qsize) as Byte 
Dim iq(1 to qsize) as Byte 


Sub Main() 
dim Data as byte
' prepare the serial channel 
Call OpenQueue(iq, SizeOf(iq)) 
Call OpenQueue(oq, SizeOf(oq)) 
Call DefineCom(comPort, rxPin, txPin, &H08) 
Call OpenCom(3, 4800, iq, oq) 


do 
Call Delay(0.05)

call getqueue(iq,data,1)
debug.print (data)

loop
End Sub
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Xbee interface

Post by dkinzer »

meenbombs wrote:Xbee TX (pin 2) to ZX pin 6. The Xbee holds it at 3.25 volts until it is transmitting and then it fluctuates a few tenths of a volt lower
The change is very likely more than a few tenths but a meter, whether analog or digital, can't register the actual "low" voltage when it occurs for short durations.

At a minimum, you almost certainly have a problem due to the Xbee output not being high enough to be reliably seen as a logic 1 by the ZX. The specification for the minimum voltage recognized as a logic 1 is 0.7 * Vcc. Since the ZX-328n is probably operating at 5 volts, this means that you need at least 3.5v to be reliably recognized as a logic 1.

The application note AN-213 External Device Interfacing addresses, among other issues, the topic of level conversions between a ZX and lower voltage devices. Figures 14 and 15 of that app note show simple level converters using only a resistor and diode or two resistors and a transistor, respectively.
- Don Kinzer
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

check also the data polarity compatibility between the two.
meenbombs
Posts: 35
Joined: 20 November 2008, 15:54 PM

Post by meenbombs »

As usual the problem was me. The ZX-328 reads the 3.3 volt serial line just fine. I just didn't notice that while I was feeding it characters it was outputting the Decimal equivilent. For anybody else with a similar problem here is a great chart to help sort out conversions
http://www.cs.mun.ca/~michael/c/ascii-table.html
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

meenbombs wrote:The ZX-328 reads the 3.3 volt serial line just fine.
Perhaps. Later, when the humidity is different, or when the temperature is different, or when you operate it in a noisier environment, or when the moon is full...it may not.

The point is that if you want your project to work reliably, you must operate the components within their published min/max specifications.
- Don Kinzer
Post Reply