Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPI driver does not control csn signal #1758

Closed
plasticassius opened this issue Dec 9, 2016 · 4 comments
Closed

SPI driver does not control csn signal #1758

plasticassius opened this issue Dec 9, 2016 · 4 comments

Comments

@plasticassius
Copy link

plasticassius commented Dec 9, 2016

Since testing with spidev_test.c passes, I dug a bit deeper and found that my csn pin is stuck high. I checked the other csn pin and it is the same. Neither does it matter which entry in the /dev directory I use.

I've described this issue in nRF24/RF24#306

lsmod | grep spi
spi_bcm2835

ls -l /dev/spi*
crw-rw---- 1 root spi 153, 0 Nov 21 21:17 /dev/spidev0.0
crw-rw---- 1 root spi 153, 1 Nov 21 21:17 /dev/spidev0.1

cat /proc/cpuinfo
processor : 0
model name : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS : 697.95
Features : half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xb76
CPU revision : 7

Hardware : BCM2708
Revision : 000d
Serial :

uname -a
Linux raspberrypi 4.4.23+ #913 Tue Oct 4 13:56:56 BST 2016 armv6l GNU/Linux

The code that doesn't work:

struct spi_ioc_transfer tr;
memset(&tr, 0, sizeof(tr));
tr.tx_buf = (unsigned long)&tx;
tr.rx_buf = (unsigned long)&tx;
tr.len = sizeof(tr);
tr.speed_hz = this->speed,	
tr.delay_usecs = 0;
tr.bits_per_word = this->bits;
tr.cs_change = 1;

ret = ioctl(this->fd, SPI_IOC_MESSAGE(1), &tr);

If I manipulate the CS pin with gpiomem driver, then the above code works for nRF24 device.

@pelwell
Copy link
Contributor

pelwell commented Dec 9, 2016

Why are you setting cs_change to 1? Although it can cause cs to change between segments of a single transfer, it has the opposite effect between transfers. See lthiery/SPI-Py#17 for another instance of the same error, and my explanation of what that flag really means.

Also:

tr.len = sizeof(tr);

looks wrong. sizeof(tx); would make more sense.

@plasticassius
Copy link
Author

Excellent! Setting cs_change to 0 did the trick! Good catch with the tr.len = sizeof(tr) typo too.

@pelwell
Copy link
Contributor

pelwell commented Jan 17, 2017

Are you happy to close this issue?

@plasticassius
Copy link
Author

Absolutely, I just hadn't noticed the close issue button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants