Ubuntu 18.04 SPI issue

Moderators: mdrjr, odroid

Ubuntu 18.04 SPI issue

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

Hi

I was trying the SPI loop back demo http://odroid.com/dokuwiki/doku.php?id=en:xu3_hardware_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
AreaScout
 
Posts: 606
Joined: Sun Jul 07, 2013 3:05 am
languages_spoken: english, german
ODROIDs: X2, U3, XU3, C2, XU4Q

Re: Ubuntu 18.04 SPI issue

Unread postby 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
odroid
Site Admin
 
Posts: 28697
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: Ubuntu 18.04 SPI issue

Unread postby 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
User avatar
AreaScout
 
Posts: 606
Joined: Sun Jul 07, 2013 3:05 am
languages_spoken: english, german
ODROIDs: X2, U3, XU3, C2, XU4Q

Re: Ubuntu 18.04 SPI issue

Unread postby 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;
....
neal
 
Posts: 148
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english


Return to Issues

Who is online

Users browsing this forum: No registered users and 2 guests