Usage – Echelon I/O Model Reference for Smart Transceivers and Neuron Chips User Manual

Page 126

Advertising
background image

116

Serial I/O Models

You can call the io_set_clock( ) function to change the clock divisor and clock edge

at run-time. You cannot change the master/slave or Neurowire/SPI modes at
run-time.

io_set_clock(

io-object-name

,

clock-value

, clockedge(

clock-code

) );

io_set_clock(

io-object-name

,

clock-value

, clockedge(

clock-code

), invert);

The

clock-value

value corresponds to the specification for the clock() keyword.

For SPI slave mode devices, the

clock-value

should be 0. The

clock-code

value

can either be a single plus character (“+”) or a single minus character (“–“), as

described under the clockedge parameter above.

Usage

unsigned short

buffer-size

;

unsigned short

buffer

[

buffer-size

];

unsigned short io_in(

io-object-name, buffer

,

buffer-size

);

unsigned short io_out(

io-object-name, buffer

,

buffer-size

);

unsigned short io_in_ready(

io-object-name

);

unsigned short io_out_ready(

io-object-name

);

unsigned short spi_get_error(

io-object-name

);

void spi_abort(

io-object-name

);

The SPI I/O object uses pins IO_8, IO_9, and IO_10 depending on the mode, as

shown in Table 46.

Table 46. Pin Use for SPI I/O Object

Mode

IO_8

IO_9

IO_10

master

Clock output

Data input

Data output

slave

Clock input

Data output

Data input

neurowire

Data output

Data input

You can use the io_in( ) and io_out( ) functions to read and write a hardware SPI

interface. This interface is very similar to the neurowire I/O model. The io_in( )
and io_out( ) calls are functionally equivalent, because SPI input and output

occur simultaneously. Because the SPI interface is full duplex, the same buffer is

used for both transmission and reception of data, with data transferred serially
out of and into the single data buffer at the same time.
A call to the io_in( ) or io_out( ) function causes the firmware to set up the

receive/transmit buffer and update the receive and transmit counts, which are
initially equal. Because the SPI model is interrupt-driven, when the SPI

transmitter is empty, the hardware transfers the first (and second if the count is

greater than 1) bytes to the hardware shift register; at this point, the transmit
count is greater by 2 than the receive count. Thus, after the call to the io_out( )

function, there are two bytes of data that have moved out of the buffer and into
the hardware.
A consequence of this transmit behavior is that if a SPI transfer by a slave device

is set up to transmit a maximum number of bytes and truncate the transfer
based on data within the transfer itself, the truncation will likely include 1 to 2

Advertising