Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
I2C Slave mode
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Forum Index -> ZX-24
Author Message
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 03 August 2008, 18:49 PM    Post subject: Reply with quote

Hi Don

I've made the change to zx-24n hardware in order to use the SPI slave mode.

After loading up the software from AN219, it appears to work, however I'm getting character errors when receiving string data back from the slave device.

I have attached a screenshot of the output. Any ideas?


Cheers

Ben



spierrors.jpg
 Description:
Errors

Download
 Filename:  spierrors.jpg
 Filesize:  62.13 KB
 Downloaded:  3267 Time(s)

Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 03 August 2008, 20:27 PM    Post subject: Reply with quote

sturgessb wrote:
I've made the change to zx-24n hardware in order to use the SPI slave mode.
Do you mean that you've modified the ZX-24n so that the SPI EEPROM is no longer activated by the slave select line? If so, what are the changes that you made?
Back to top
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 03 August 2008, 20:36 PM    Post subject: Reply with quote

Yes, I cut the trace indicated by Tom Becker.

On the master I'm requesting an 11 character string (stored on the slave).

string on slave is "aaaa bbbbbb"

If on the master I request it more than 10 times a second I start to get rogue characters, and/or missing characters in around 10% of the return strings.

There is no other code running on the devices, just code for this.

Is it a speed issue? how fast can this SPI slave stuff be run?

I need to transfer around 60 bytes from slave to master at 40hz, is this possible?
Back to top
GTBecker



Joined: 18 Jan 2006
Posts: 472
Location: Cape Coral

Posted: 03 August 2008, 20:57 PM    Post subject: I2C Slave mode Reply with quote

Quote:

> ... I cut the trace indicated by Tom Becker.


http://www.zbasic.net/forum/download-266.html

That cut actually severs SO from the EEPROM. Its /CS is still active.


Tom
Back to top
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 03 August 2008, 21:01 PM    Post subject: Reply with quote

its strange, sometimes it runs at highish speed (50hz) for a minute or so without any error, and then they start appearing.

general rule of thumb, get better results when cold start
Back to top
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 03 August 2008, 21:08 PM    Post subject: Reply with quote

on further fiddling....

it seems Bit Rate of f/64 is a must, anything else doesn't work, is this correct?

Also, if I extend the rxDelay from 4 to 10, i get stable output.

So is it just a case of the slave device not being able to prepare the data in time?
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 03 August 2008, 21:19 PM    Post subject: Reply with quote

sturgessb wrote:
sometimes it runs at highish speed (50hz) for a minute or so without any error, and then they start appearing.
Try slowing down the SPI clock one notch. The SPI slave test driver used the call below to initialize the channel. Changing the second parameter to &H03 will yield an SPI clock of 14.7MHz / 128 = 115.2KHz. That's 8.6uS per bit.
Code:
Call OpenSPI(chan, &H02, csPin, 4)


Separately, you might try increasing the slave read delay (the fourth parameter). Note that the units of this parameter is SPI clock cycles so slowing down the clock also increases the slave read delay.
Back to top
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 03 August 2008, 21:44 PM    Post subject: Reply with quote

Cool thanks Don, I think I've found the sweet spot for it to work.

On another note. Would it be possible to receive a String from the slave unit without having to request the length first? Could it do this dynamically at the master as the data comes in?

I only ask as I am trying to make a generic send_string function so it would be good to make this a bit more dynamic, rather than having to have a state for each get string length and each string send.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 03 August 2008, 22:47 PM    Post subject: Reply with quote

sturgessb wrote:
It seems Bit Rate of f/64 is a must, anything else doesn't work, is this correct?
With the example code accompanying the application note, that is what I observed. If you add more code to the ISR you may need to add more delay or slow the clock further.

The issue is that the slave requires time to respond to each interrupt. If you use a clock rate that is too high, the data comes in faster than it can be handled by the slave. Similarly, the slave read delay allows time for the slave to prepare the data to send back.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 03 August 2008, 22:57 PM    Post subject: Reply with quote

sturgessb wrote:
Would it be possible to receive a String from the slave unit without having to request the length first? Could it do this dynamically at the master as the data comes in?
Not with the current design of the SPICmd() API. There is no way to say "stop sending data whenever you want" and, even if there were, there is no way for the master to know how many bytes were actually sent.

If you know the maximum string length, you could use a generic command and have the slave place the length in the first byte, followed by the string data, followed by filler. This would simplify things for you at the expense of consuming more time for the transaction.

Of course, you can write your own routines for sending/receiving data by manipulating the SPI controller registers directly. If you do that, you can easily implement an interface where the slave's first response byte indicates how many more bytes are to come and then you just stop after you've received the indicated number.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZX-24 Time synchro. with the server - Timezone/DST with your computer
Goto page Previous  1, 2
Page 2 of 2

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group