SPI devName

Post Reply
Sebas_Ledesma
Posts: 95
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 4 times
Been thanked: 2 times
Contact:

SPI devName

Unread post by Sebas_Ledesma » Fri Oct 11, 2019 4:14 am

Hi:

I´m working to manage an 256x64 OLED display trought SPI, so I followed the instrucions available at
https://wiki.odroid.com/odroid-c2/appli ... _odroid-c2

First tests are ok, the only thing that I've noticed its that the device name it's not named spidev0.0 nor spidev1.0
instead when executing ls /dev/spidev*
I get:

Code: Select all

/dev/spidev32766.0
It's a bug or I can trust that the name will remain with future updates?


Thanks in advance
Sebas

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

Re: SPI devName

Unread post by odroid » Fri Oct 11, 2019 9:17 am

Very weird.
Do you run Kernel 3.16.72-46?

Sebas_Ledesma
Posts: 95
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: SPI devName

Unread post by Sebas_Ledesma » Sat Oct 12, 2019 12:19 am

Yes. I when calling uname -a i get:
Linux myDevice 3.16.72-46 #1 SMP PREEMPT Tue Aug 13 18:09:58 -03 2019 aarch64 aarch64 aarch64 GNU/Linux

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

Re: SPI devName

Unread post by odroid » Sat Oct 12, 2019 10:12 am

Show me "lsmout" output.

User avatar
mad_ady
Posts: 6674
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 194 times
Been thanked: 148 times
Contact:

Re: SPI devName

Unread post by mad_ady » Sun Oct 13, 2019 2:30 am

I believe @odroid meant lsmod

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

Re: SPI devName

Unread post by odroid » Mon Oct 14, 2019 9:30 am

Right. :oops:

Sebas_Ledesma
Posts: 95
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: SPI devName

Unread post by Sebas_Ledesma » Mon Oct 14, 2019 10:21 pm

Here it's lsmod output:

Code: Select all

odroid@mx2200:~$ lsmod
Module                  Size  Used by
spidev                  6675  0
spi_gpio                6543  0
spi_bitbang             4031  1 spi_gpio
fuse                   90892  3
squashfs               32435  0
w1_gpio                 3801  0
wire                   28614  1 w1_gpio
gxbb_wdt                3395  0
meson_gpiomem           4040  0
sch_fq_codel            7827  2
ip_tables              17220  0
ipv6                  387317  24
autofs4                27592  2
Sebas

Sebas_Ledesma
Posts: 95
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: SPI devName

Unread post by Sebas_Ledesma » Tue Oct 15, 2019 4:59 am

One more issue. It seems that the SPI implementation dont support 3WIRE mode.
I've modified the dot_test.c example available here: https://odroid.com/dokuwiki/doku.php?id=en:c2_dotmatrix

Code: Select all

static const char *device_spidev0_0 = "/dev/spidev32766.0";
static uint8_t mode= 0;

main() {
...
    /* SPI mode */
	mode |= SPI_3WIRE;	
    ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
    if (ret == -1)
        pabort("Can't set SPI mode");
...
    }
It compiles fine, but when executed I get:
Can't set SPI mode: Invalid argument.
Initializing with mode = 0, dont report anything but my display shows nothing.

Sebas

Sebas_Ledesma
Posts: 95
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: SPI devName

Unread post by Sebas_Ledesma » Tue Oct 15, 2019 5:04 am

The very same happens when executing

Code: Select all

sudo ./spidev_test -D /dev/spidev32766.0 -3
The output is:

Code: Select all

can't set SPI mode: invalid argument.
Aborted
Sebas

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

Re: SPI devName

Unread post by odroid » Tue Oct 15, 2019 9:54 am

Add the following two driver in /etc/modprobe.d/blacklist-odroid.conf file and try again.

Code: Select all

w1_gpio                 3801  0
wire                   28614  1 w1_gpio
Meanwhile, we will try it here too.

User avatar
tony.hong
Posts: 42
Joined: Tue Jun 04, 2019 1:49 pm
languages_spoken: korean
ODROIDs: All
Location: korea
Has thanked: 9 times
Been thanked: 8 times
Contact:

Re: SPI devName

Unread post by tony.hong » Tue Oct 15, 2019 6:49 pm

Hi Sebas_Ledesma.

SPI works fine even if the bus number is 32766.
But I think that the number confuse you or others because it doesn't match the wiki.
I'm going to correct this.

I don't know a cause of the 3-wire SPI problem yet.
I guess that software SPI(spi_bitbang) doesn't support 3-wire.
After some testing or researching, I will reply.

Sebas_Ledesma
Posts: 95
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: SPI devName

Unread post by Sebas_Ledesma » Tue Oct 15, 2019 11:17 pm

Thanks for your reply.

I've modified my hardware to use a GPIO 6 (Pin 22) as Data/~Command selector.
I've tried before manually stuffing the bits to add the 9th (Data/~Command) and so implementing 3wire mode but it doesnt seems to work as I have to transmit a full byte, and I dont know what effect will ocurr in the SPI display when receiving the extra dummy bits.

Sebas

Sebas_Ledesma
Posts: 95
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: SPI devName

Unread post by Sebas_Ledesma » Wed Oct 16, 2019 5:31 am

I can confirm that the SPI bus it's working.

I've changed my hardware to use "4 lines" mode:
PIN 19 = SPI Master Out Slave Input (MOSI)
PIN 21 = SPI Master in Slave Out (MISO) **unused in my case as my display it's write only**
PIN 22 = GPIO 6 -> Data / !Command
PIN 23 = SPI Serial Clock (SCLK)
PIN 24 = SPI Chip Select
PIN 18 = GPIO 5 -> Display RESET

Code: Select all

#define MY_SPI_RESET	5	//pin 18
#define MY_SPI_DC		6	//Data / !Command, pin 22
#define MY_SPI_CS		10  //pin 24
...

void Write_Instruction(int fd,  unsigned char cmd) {
	//Poner PIN data/cmd en 0
	digitalWrite(MY_SPI_DC, 0);

    int ret;
    uint8_t tx[] = { cmd  };
    uint8_t rx[ARRAY_SIZE(tx)] = {0, };

    struct spi_ioc_transfer tr;

    memset(&tr, 0, sizeof(tr));
    tr.tx_buf = (unsigned long)tx;
    tr.rx_buf = (unsigned long)0;
    tr.len = ARRAY_SIZE(tx);
    tr.speed_hz = speed;
    tr.bits_per_word = bits;
    tr.delay_usecs = 1; //Probably we can use 0
    tr.cs_change = 1;  //Probably we can use 0

    ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
    if (ret < 1)
        fprintf (stderr, "%s: can't send SPI message\n", __func__);

	digitalWrite(MY_SPI_DC, 1);
} 


void Write_Data(int fd,  unsigned char data) {
	//Poner PIN data/cmd en 1
	digitalWrite(MY_SPI_DC, 1);

    int ret;
    uint8_t tx[] = { data };
    uint8_t rx[ARRAY_SIZE(tx)] = {0, };

    struct spi_ioc_transfer tr;

    memset(&tr, 0, sizeof(tr));
    tr.tx_buf = (unsigned long)tx;
    tr.rx_buf = (unsigned long)0;
    tr.len = ARRAY_SIZE(tx);
    tr.speed_hz = speed;
    tr.bits_per_word = bits;
    tr.delay_usecs = 1;  //Probably we can use 0
    tr.cs_change = 1;  //Probably we can use 0

    ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
    if (ret < 1)
        fprintf (stderr, "%s: can't send SPI message\n", __func__);
} 
So far no need to blacklist the w1_gpio and wire modules.

Sebas

Sebas_Ledesma
Posts: 95
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: SPI devName

Unread post by Sebas_Ledesma » Wed Oct 16, 2019 6:49 am

What is the maximun speed possible with SPI (bitbanging mode)?
I used 500Khz and 1Mhz, but the display refresh (256 * 64 * 4 bits) it's slows.
A full clear takes around 300 ms (eye mesaurement).

Sebas

User avatar
tony.hong
Posts: 42
Joined: Tue Jun 04, 2019 1:49 pm
languages_spoken: korean
ODROIDs: All
Location: korea
Has thanked: 9 times
Been thanked: 8 times
Contact:

Re: SPI devName

Unread post by tony.hong » Wed Oct 16, 2019 8:37 am

Glad to be solved.

When C2 is set to 500 kHz, it is actually operating at 390KHz.
Ref:https://wiki.odroid.com/accessory/displ ... &s[]=speed

Sebas_Ledesma
Posts: 95
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: SPI devName

Unread post by Sebas_Ledesma » Thu Oct 17, 2019 5:07 am

There is any way to increase the speed?
RPi allows 32Mhz and we are a little limited with 390Khz.

Sebas

User avatar
mad_ady
Posts: 6674
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 194 times
Been thanked: 148 times
Contact:

Re: SPI devName

Unread post by mad_ady » Thu Oct 17, 2019 1:12 pm

The hardware spi is used for ethernet, so you're left only with software bitbanged spi which is much slower

User avatar
tony.hong
Posts: 42
Joined: Tue Jun 04, 2019 1:49 pm
languages_spoken: korean
ODROIDs: All
Location: korea
Has thanked: 9 times
Been thanked: 8 times
Contact:

Re: SPI devName

Unread post by tony.hong » Fri Oct 18, 2019 7:16 pm

I confirmed that spi-max-frequency is set to 500kHz.
Maybe it is difficult to increase the speed.
And I added some code to set the SPI device name to spidev0.0, but don't know yet about 3-wire problem.

Sebas_Ledesma
Posts: 95
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: SPI devName

Unread post by Sebas_Ledesma » Sat Oct 19, 2019 1:29 am

Thanks!
3-wire it's not that important for us, as 4-wire it's slightly faster.
Also to have the correct name will help us to move our code to H2 / N2 eventually.

Sebas

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 6 guests