Ubuntu 18.04 SPI issue

Post Reply
User avatar
AreaScout
Posts: 959
Joined: Sun Jul 07, 2013 3:05 am
languages_spoken: german, english
ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
N1, Go, VU5A, Show2, CloudShell2,
H2, N2, VU7A, VuShell
Has thanked: 10 times
Been thanked: 20 times
Contact:

Ubuntu 18.04 SPI issue

Unread post by AreaScout » Fri May 04, 2018 12:02 am

Hi

I was trying the SPI loop back demo http://odroid.com/dokuwiki/doku.php?id= ... rdware_spi by shorten pin 7 and 9, it did work only one out of three tries, sometimes it's even worse

Code: Select all

 
./spi_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
can't send spi message: Invalid argument
Aborted
root@odroid:/home/odroid# ./spi_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
can't send spi message: Invalid argument
Aborted
root@odroid:/home/odroid# ./spi_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

AB 00 00 00
why does that happen ?

RG

User avatar
odroid
Site Admin
Posts: 31058
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 28 times
Been thanked: 145 times
Contact:

Re: Ubuntu 18.04 SPI issue

Unread post by odroid » Fri May 04, 2018 8:21 am

Change the buffer size option in the SPI driver buffer size.
viewtopic.php?f=97&t=30582#p220270

User avatar
AreaScout
Posts: 959
Joined: Sun Jul 07, 2013 3:05 am
languages_spoken: german, english
ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
N1, Go, VU5A, Show2, CloudShell2,
H2, N2, VU7A, VuShell
Has thanked: 10 times
Been thanked: 20 times
Contact:

Re: Ubuntu 18.04 SPI issue

Unread post by AreaScout » Fri May 04, 2018 6:00 pm

odroid wrote:Change the buffer size option in the SPI driver buffer size.
viewtopic.php?f=97&t=30582#p220270
Thank you for the link, but the problem described there is different from mine, the error reported was 'Invalid argument' to it's ioctl, i have played around with that SPI_IOC_MESSAGE and it seems that if the array dimension
of spi_ioc_transfer is greater then one, it fails.

If i change line 59 from ret = ioctl(fd, SPI_IOC_MESSAGE(2), tr); to ret = ioctl(fd, SPI_IOC_MESSAGE(1), tr); it works, maybe this is a small hint where it could fail !?

RG

neal
Posts: 182
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Ubuntu 18.04 SPI issue

Unread post by neal » Wed May 16, 2018 4:48 pm

Hi, AreaScout

Can you add as below initializing code(memset()) of variable and then try again?

Code: Select all

static void transfer(int fd)                                                    
{                                                                               
       int ret;                                                                
       uint8_t tx[] = {                                                        
               0xAB, 0x00, 0x00, 0x00                                          
       };                                                                      
       uint8_t rx[ARRAY_SIZE(tx)] = {0, };                                     

       struct spi_ioc_transfer tr[2];                                          

// ********************************** Add this
memset(tr, 0x00, sizeof(tr));
// **********************************

       tr[0].tx_buf = (unsigned long)tx;
       tr[0].rx_buf = (unsigned long)rx;                                       
       tr[0].len = ARRAY_SIZE(tx);                                             
       tr[0].speed_hz = speed;                                                 
       tr[0].bits_per_word = bits;                                             
       tr[0].delay_usecs = 0;
       tr[0].cs_change = 0;
....

Post Reply

Return to “Issues”

Who is online

Users browsing this forum: No registered users and 1 guest