Confirmation of SPI config on EMX please


I am trying to get some spi hw working using emx,.

We are using the spi2 bus, pin(58,59,61), on the emx,

based on all my readings I should be using the following config, which uses SPI.SPI_module.SPI2 as the module

SPI.Configuration MyConfig = new SPI.Configuration((Cpu.Pin)EMX.Pin.IO54,
         false, 100, 5, false, true, 4000, SPI.SPI_module.SPI2);

my CS to the device is on 54,

thanks for confirming. I hate hw bringup… :slight_smile:

Also, are there any really good examples on how to read/write single registers via SPI in this
All I need to do is simple 8 bit writes / reads…

You are correct. Have you seen the the SPI tutorial here Support – GHI Electronics

Thanks, I have seen that example, and am still not sure I am doing my writes correctly.

at the bottom is a bit example code provided by the spi device mfg(NXP SC16IS75X),
for talking with the device via a 8051 mcu,

Here is an example of how I am trying to write a 0x80 to the LCR register,
is this correct, , can I do it via one call to the write routine using a 2 byte buffer?,
Thanks for any help / insight you can provide,

byte[] tx_data = new byte[1];
tx_data[0] = NXP_Comm.LCR;
tx_data[0] <<= 3; // register address byte
tx_data[0] = 0x80;

char SPI_send (char byte) { // mcu sends a byte to spi bus
SPDAT = byte; // data is sent
while(!SPI_tx_completed); // wait end of transmission
SPSTAT &= ~0x80; // clear mcu spi interrupt flag (SPIF)
SPI_tx_completed = 0; // clear transmit spi interrupt flag
return SPDAT; // receive data on spi read

char SPI_read (char register) { // mcu reads a register from SC16IS750
SPI_SS = 0; // enable slave chip select
SPI_send((register<<3) | 0x80); // register address is sent
register = SPI_send(0); // dummy data is sent for spi read
SPI_SS = 1; // disable slave chip select
return register; // receive the read data

void SPI_write (char address, char data) { // mcu writes data to SC16IS750
SPI_SS = 0; // enable slave chip select
SPI_send (address<<3); // address is sent
SPI_send (data); // data is sent
SPI_SS = 1; // disable slave chip select

Please ignore my question below about the writes , I dug into the forum and found
the answer, – I should just use a single call to write with a buffer that contains
the addr / data…

if you have any other insights thought or any other specific example please send my way.


The “code” tags (the 101010 icon in a reply) formats your text as code, please use it (modify your existing post to set that too)

I know nothing about your chip.

SPI write two bytes needs you to do two things. Create a two-byte array with your data, and do one write.

byte[] tx_data = new byte[2];
 tx_data[0] = NXP_Comm.LCR <<3; // why does it shift 3 bits ? 
tx_data[1] = 0x80;

That should write the register address and 0x80, assuming you have NXP_Comm.LCR set right. You should explicitly check what value that should be from a datasheet.

edit: I see you’ve added a new post while I was typing :slight_smile: