sliver80
Posts: 2
Joined: Wed Dec 02, 2015 11:34 am

Pi4J CS management

Wed Dec 02, 2015 11:47 am

Hi,
i'm using Pi4J to control an SPI device.
Ports and code are ok, i sent data correctly and receive answer from the device but the answer is wrong.

Looking from the vendor specification, they tell that between every sent byte (the request commands have length of 10 bytes) the CS line must be switched high for at least 1 us (and then again low during the byte transmission).

Could be this the problem of the wrong answer received?
Is there a specific parameter / method to be used to manage this behavior or is it managed automatically by the library?

thanks in advance

User avatar
joan
Posts: 14019
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Pi4J CS management

Wed Dec 02, 2015 3:01 pm

That sounds like an odd device. Have you got a link to the specs so that your understanding can be confirmed?

sliver80
Posts: 2
Joined: Wed Dec 02, 2015 11:34 am

Re: Pi4J CS management

Thu Dec 03, 2015 6:52 am

they used the MKL25Z128VLH4 microcontroller to build the board.
in the mc spec at page 41:
http://cache.freescale.com/files/32bit/ ... M48SF0.pdf
the SS goes high after a byte is sent.

User avatar
joan
Posts: 14019
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Pi4J CS management

Thu Dec 03, 2015 8:46 am

In that case you'll have to send the bytes individually. so for 10 bytes you will need 10 SPI transfers.

I think you can send multiple SPI requests using the spi_ioc_transfer struct but I'm not aware of any library or driver support for that feature.

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Pi4J CS management

Thu Dec 10, 2015 11:50 pm

I just worked on a project with similar SPI communication requirements. I had to implement this in C to take advantage of the more complex transfer options. The native SPI transfer object (http://lxr.free-electrons.com/ident?i=spi_ioc_transfer) does have a "cs_change" flag you can set to toggle the CS state. You can create multiple SPI transfers enclosed in a single SPI messages and use the IOCTL calls to send the message to the spidev device.

But no, Pi4J does not provide this capability through it's APIs.

Like Joan suggested, you could use the library and just send your individual bytes one per transfer.

Thanks, Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

Return to “Java”