Power & Source of Big Ideas

Allwinner H3 SPIDEV issue

Moderators: chensy, FATechsupport

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.
Image

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

Code: Select all

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 help me out!
Hello! I made it using https://github.com/nRF24/RF24/ library, but with fixed SPIDEV driver. I will make a fork of this library in a few days/week and post a link. BTW: There is a problems with SPI in current official build (that you already saw), so I used last armbian build https://www.armbian.com/nanopi-neo-2/
Thanks for the help. I am using H3 board. Not H5. So that image is not compatible. However, i will try to dig up sources and see if I can find the differences in spidev.c files.

Can you copy paste the code of spidev.c here so I can find the issue. Thanks a lot!
https://github.com/sashok1337/RF24/comm ... f5964df559

It's all my changes to get it work. You can download my repo with latest changes and try it, but I think that you also need to change kernel version/build.
Thanks, I tried your code but I'm facing the same issue. The red arrows indicate invalid clock state, green arrow indicate correct clock state.
Image

kernel version is 4.11.2

I'm confident that this is a SPIDEV kernel driver issue. RF24 library seems okay. If I use https://pypi.python.org/pypi/spidev, i get the same issue. so this has to do with kernel driver files. If someone has experience debugging kernel drivers, please help me out.

I've looked up the h3 datasheet so far and can only verify the register offset addresses with those defined in the kernel device tree.
That's exactly what I talking about. I had the same picture on my logic analizer with latest 'official' (kernel 4.11.2) friendlyarm's OS build, and I even wrote a comment in this thread http://www.friendlyarm.com/Forum/viewtopic.php?f=47&t=856 (latest answer). And moving to last armbian OS build based on new kernel version (4.14) is worked for me.

As I see armbian builds are available for H3-based devices (https://www.armbian.com/download/).

This forum is semi-dead, so I doubt that someone will help to fix this issue :( But let's believe in a miracle :roll:

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests (based on users active over the past 5 minutes)
Most users ever online was 102 on Mon Oct 08, 2018 12:42 pm

Users browsing this forum: No registered users and 4 guests