SPI on ZX-24x

Discussion specific to the 24-pin ZX microcontrollers, e.g. ZX-24r, ZX-24s and ZX-24t.
Post Reply
codeferret
Posts: 12
Joined: 03 January 2012, 15:07 PM

SPI on ZX-24x

Post by codeferret »

I have a ZX-24x module and am confused by the documentation. Page 201 of the most recent system library document says:
Note that any general purpose I/O pin of the device may be used as the slave select pin except for the SS pin of the device.
OK... so the only pin that I'm not allowed to use as a slave select... is the piece of hardware dedicated to that purpose?! There is even a terminal on the end of the board for SS - why is it there, if I am not supposed to use it? I must have missed something!

The ZX-24x does not have any memory that uses the SPI port, so it seems like it would be harmless enough for me to use it as intended.

If I am in fact allowed to use the SS pin for SS purposes (with the ZX-24x being the master), how can I specify it in the OpenSPI() call?

Right now, I am invoking:

Code: Select all

OpenSPI( 1, 0, 11 )
and this is working just fine, except that I don't understand why I can use the clock, MOSI, and MISO terminals at the end of the board, but have to leave SS alone and use a GPIO pin for SS.

Also, page 24 of the system library manual says there's a channel zero - to what terminals would SPI channel 0 be attached? In reality, when I hook up a scope to look at signals, channel 1 seems to be using the pins for channel 0 on that page 24 tabl=... I am very confused.

Any help appreciated.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: SPI on ZX-24x

Post by dkinzer »

codeferret wrote:[S]o the only pin that I'm not allowed to use as a slave select... is the piece of hardware dedicated to that purpose?!
Most AVRs can operate as an SPI master or as an SPI slave. When acting as a master, there may be multiple SPI slaves attachead and each slave must have a separate line to select it. When acting as an SPI slave, the AVR will be selected when its SS line is taken low.

The admonition about not using the SS line doesn't apply generally now. Rather, it applies only to those devices that use an external SPI EEPROM for ZBasic Program Memory. Otherwise, the only restriction is that the SS line must either be configured as an output (possibly being used as a slave select signal) or must be held high for the duration of SPI operations. The reason for this restriction is that if the SPI controller is active and the SS pin for that controller is an input low the controller switches to slave mode even if it had been operating as a master.
codeferret wrote:Also, page 24 of the system library manual says there's a channel zero - to what terminals would SPI channel 0 be attached?
All ZX devices support up to 4 "channels" using the default (or only) hardware SPI controller. For xmega-based ZX devices, which all have multiple hardware SPI controllers, the controller associated with port D is used by default. As described on the page for OpenSPI(), the index of the desired hardware controller may be passed as the high byte of the flags parameter: 0->PortD, 1->PortC, 2->PortE, 3->PortF.
- Don Kinzer
codeferret
Posts: 12
Joined: 03 January 2012, 15:07 PM

Re: SPI on ZX-24x

Post by codeferret »

Thanks Don. I'm still a little confused.

For the ZX-24x, not having an external memory, does that mean I can use the SS terminal as the master's slave selector output when in master mode, or is it purely a slave mode input?

If I can use the SS pin as the master's slave selector output in master mode, how is it specified in the third argument of OpenSPI(), since it doesn't have a pin number?

If the desired SPI channel index can be passed using the high byte of flags, how does that differ from the first argument of OpenSPI()?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: SPI on ZX-24x

Post by dkinzer »

codeferret wrote:[D]oes that mean I can use the SS terminal as the master's slave selector output when in master mode[...]?
Yes. The only requirement is that SS is either an output or held high during SPI transactions.
codeferret wrote:If I can use the SS pin as the master's slave selector output in master mode, how is it specified in the third argument of OpenSPI(), since it doesn't have a pin number?
Use its port.pin designator, e.g. D.4.
codeferret wrote:If the desired SPI channel index can be passed using the high byte of flags, how does that differ from the first argument of OpenSPI()?
The SPI controller index (passed in the high byte of flags) is completely different from the channel index passed as the first parameter to OpenSPI(). All ZX devices can use channels 1-4 but only xmega devices can specify a specific controller in the high byte of flags.
- Don Kinzer
codeferret
Posts: 12
Joined: 03 January 2012, 15:07 PM

Re: SPI on ZX-24x

Post by codeferret »

Thanks!
Post Reply