2 2
azmathmoosa

NanoPi Neo SPIDEV SCK issue

Recommended Posts

Hi,  I have a nanopi neo based on allwinner h3 chipset.  I am trying to use an SPIDEV based driver for RF2401L (2.4 Ghz wireless module).  I have used npi-config to enable the /dev/spidev0.0 device.  However, when I try to use it to read status register of my module, I get wrong values.

My SPI settings are

Speed: 10kHz

Bits: 8

Mode: 0 (CPOL=0, CPHA=0)

 

To debug the issue I used a logic analyzer and found the clock signal rising up just before the MISO/MOSI activity.  It shouldn't do that.  When CPOL = 0, clock should be idle at 0.

H1muVZw.jpg

 

I am setting the SPI mode to 0.  Here is the code

void SPI::init()
{
uint8_t bits = RF24_SPIDEV_BITS;
uint32_t speed = RF24_SPIDEV_SPEED;
uint8_t mode = 0;
int ret;
/*
* spi mode
*/
ret = ioctl(this->fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
{
perror("can't set spi mode");
abort();
}
ret = ioctl(this->fd, SPI_IOC_RD_MODE, &mode);
if (ret == -1)
{
perror("can't set spi mode");
abort();
}
/*
* bits per word
*/
ret = ioctl(this->fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
if (ret == -1)
{
perror("can't set bits per word");
abort();
}
ret = ioctl(this->fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
if (ret == -1)
{
perror("can't set bits per word");
abort();
}
/*
* max speed hz
*/
ret = ioctl(this->fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if (ret == -1)
{
perror("can't set max speed hz");
abort();
}
ret = ioctl(this->fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
if (ret == -1)
{
perror("can't set max speed hz");
abort();
}
}

 

 

Please someone help!  

Share this post


Link to post
Share on other sites

Hi,

   I notice the same problem in a Orange PI ZERO. SCLK is high when CS is asserted but as you say it should be LOW before CS is asserted.   I have found no solution for this issue. The very strange thing is that on the OPI ZERO it happens only on the second CS line. I'm using the same RF24 code so the problem is not in the library. It should be in the spidev driver.

 

In the Opi Zero I use the SPI1 instead the SPI0. Using spi-spidev and spi-add-cs1 overlays.  If plug the radio to /dev/spidev1.0 it works fine without problems but if I change the radio to /dev/spidev1.1 the logic analyzer shows the same SCLK problem. :o  I do not know why but there something wrong here.

 

Try to change SPI interface or the CS you are connecting the radio.  This could be workarround.

 

 

Maybe @martinayotte

or @zador.blood.stained

hav more information on the SPIDEV implementation as I have seen in the past that they have deep knowledge on that.

 

Regards,

 

 

 

Share this post


Link to post
Share on other sites

Thanks for the info.  So this issue might have something to do with the board design itself and not with the kernel driver or H3 itself.  In NanoPi Neo, only SPI0 is exposed.   So there is only spidev0.0.  Will have to try a different Pi board then.  It's sad cause NanoPi Neo is cheap and excellent otherwise.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
2 2