Com4, what am i doing wrong??

Discussion specific to the ZX-1281 and ZX-1280 microcontrollers as well as the ZX-1281 and ZX-1280 Dev Boards.
Post Reply
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Com4, what am i doing wrong??

Post by sturgessb »

Hi

I am trying to read an RFID chip on com4 on a zx128ne

I have tested the output of the rfid chip on my logic analyser, and all is good with correct data coming out. 9600baud TTL inverted

here is the datasheet
http://www.sparkfun.com/datasheets/Sens ... asheet.pdf

However I cant get the zx to read it with com4, this is the code i have...

Code: Select all

PUBLIC com3TXQueue(1 to 32) as Byte 
PUBLIC com4RXQueue(1 to 100) as Byte 

PUBLIC CONST com3tx_pn as Byte = 15
PUBLIC CONST com4rx_pn as Byte = 14



Sub Main()
        'setup software coms
	Call ComChannels(2, 9600)
	
	'OPEN COM3 - for lcd
	Call OpenQueue(com3TXQueue, SizeOf(com3TXQueue))
	Call DefineCom(3, 0, com3tx_pn, &H08)
	Call OpenCom(3, 9600, 0, com3TXQueue)
	
	'OPEN COM4 - for rfid
	Call OpenQueue(com4RXQueue, SizeOf(com4RXQueue))
	Call DefineCom(4, com4rx_pn, 0, &H80)
	Call OpenCom(4, 9600, com4RXQueue, 0)


Do
	if GetQueueCount(com4RXQueue) > 0 then
              Debug.print  GetQueueStr(com4RXQueue)
        end if
        Call Sleep(0.1)
Loop

What am i missing?

Cheers

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

Re: Com4, what am i doing wrong??

Post by dkinzer »

sturgessb wrote:What am i missing?
Perhaps this post about inverted mode problems.
- Don Kinzer
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

Thanks Don

But I have uninstalled the IDE and installed latest 3.0.2 version, and getting the same problem :(

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

Post by dkinzer »

sturgessb wrote:But I have uninstalled the IDE and installed latest 3.0.2 version, and getting the same problem.
If you do only that, you will indeed continue to have the same problem. Note that the correction for the inverted mode problem is present only in the ZX Library v3.0.5 and later. The ZX Library that gets installed with the current installer is v3.0.4. We didn't update the installer because we thought that we would have a new release sooner than we've been able to.

The special ZX Library update is the fifth entry on the Downloads Page. Just download the .zip file and extract the files to the zxlib subdirectory of the ZBasic installation directory.
- Don Kinzer
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

Sorry Don.

But still, with 3.0.5, same problem :(

perhaps the bug still exists for 128?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

sturgessb wrote:perhaps the bug still exists for 128?
It is remotely possible but not likely, I think. Does a re-compiled application sign on with v3.0.5 or v3.0.4?
- Don Kinzer
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

3.0.5

for sanity sake (to check i didnt have a bad pin etc) i changed the opencom to be non-inverted. So you know, this works, so its definitely the problem.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

sturgessb wrote:So you know, this works, so its definitely the problem.
Thanks for devising this test.
I rebuilt the ZX Library and verified that the updated SW UART code was re-compiled for the ZX-128ne (and all other devices as well). I posted this as v3.0.6 just to avoid any confusion. Download that, extract it to the ZBasic/zxlib subdirectory and see if that rectifies the problem.
- Don Kinzer
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

thanks Don, will test this tonight.

Cheers

Ben
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

sorry Don, still no joy with 3.0.6

Call DefineCom(4, com4rx_pn, 0, &H08) works

Call DefineCom(4, com4rx_pn, 0, &H80) does not
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

sturgessb wrote:Call DefineCom(4, com4rx_pn, 0, &H80) does not
If that's actually the value you're using for the fourth parameter then that is the problem - it should be &H88 for inverted, 8-bit. The only two legal values for the least significant four bits are 7 and 8; all other values result in silent failure.
- Don Kinzer
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

Arghhh and I though I was getting better at this stuff!

The zx system library reference manual says &H80 for inverted, i thought 8 bit was standard and therefore didnt need to be specified.

Crap, im sorry for wasting your time Don
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

sturgessb wrote:i thought 8 bit was standard and therefore didnt need to be specified.
Just to be clear, the "Serial Channel Configuration Flag Values" table in the description of DefineCom() describes several fields which can be combined to get the desired effect. The value &H08 means "non-inverted, no parity, 8-bit" while the value &H88 mean "inverted, no parity, 8-bit".

This same concept is used in the description of bit fields for several ZBasic System Library routines including DefineX10(), ShiftInEx(), ShiftOutEx(), etc.
- Don Kinzer
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

I should have known that, school boy error. Its a bugger we didnt spot that error in my code in first post.

When i change it to &H88 i just get giberish so i have no bloody idea whats going on, the spec sheet for the rfid must be wrong as i get a correct value when set to non-inverted

However, it doesnt matter, the value is the same everytime, and thats whats important, so I dont want to waste any more of your time.

Ben
Post Reply