OSError: [Errno 22] EINVAL for SPI operation

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

OSError: [Errno 22] EINVAL for SPI operation

Post by Yadnik » Fri Jul 30, 2021 8:13 pm

I am trying to run an accelerometer sensor using the SPI class, however I am getting an error as follows:
Traceback (most recent call last):
File "<stdin>", line 77, in <module>
File "<stdin>", line 64, in reg_read
OSError: [Errno 22] EINVAL
The code to my driver program can be found here: https://github.com/Yadnik1/Accel-10-cli ... 20click.py
It would be very helpful if someone can please tell me the mistake I am making.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: OSError: [Errno 22] EINVAL for SPI operation

Post by davef » Fri Jul 30, 2021 9:51 pm

I am only guessing here ... is the error to do with <cs>. Maybe it needs to be global.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: OSError: [Errno 22] EINVAL for SPI operation

Post by jimmo » Wed Aug 04, 2021 5:03 am

Yadnik wrote:
Fri Jul 30, 2021 8:13 pm
It would be very helpful if someone can please tell me the mistake I am making.
This is being returned from Zephyr -- i.e. spi_transceive is returning EINVAL...

Do any SPI operations work? (e.g. read). Does it work if you use SoftSPI instead?

Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Re: OSError: [Errno 22] EINVAL for SPI operation

Post by Yadnik » Fri Aug 06, 2021 8:45 am

I tried basic SPI commands, the program is as follows:
from machine import SPI,Pin
spi = SPI("SPI_0")
cs = Pin(("GPIO_0", 8), Pin.OUT)
msg = bytearray()
spi.write(msg)

This too returns an error:
File "<stdin>", line 5, in <module>
OSError: [Errno 22] EINVAL

I tried making changes to the device tree file as well and also tried it on an alternative board having the Zephyr port.(CC1352R launchxl),
However I am getting the same error.Can you please have a look and suggest what may be going wrong.

Thank you!!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: OSError: [Errno 22] EINVAL for SPI operation

Post by jimmo » Fri Aug 06, 2021 2:07 pm

Can you try SoftSPI and see if that works?

Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Re: OSError: [Errno 22] EINVAL for SPI operation

Post by Yadnik » Sun Aug 08, 2021 11:08 am

I tried taking SoftSPI into use, however the module does not exist.I get this error:
ImportError: can't import name SoftSPI

Any other factor that I can look into?I am also trying to look into Zephyr part of things.
Thank you!!

Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Re: OSError: [Errno 22] EINVAL for SPI operation

Post by Yadnik » Mon Aug 09, 2021 11:11 am

Is there a way that we can tell from this file:https://github.com/micropython/micropyt ... hine_spi.c
whether these modules are added or not?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: OSError: [Errno 22] EINVAL for SPI operation

Post by Roberthh » Mon Aug 09, 2021 11:51 am

import machine
dir (machine)

Will tell you all classes on machine.

Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Re: OSError: [Errno 22] EINVAL for SPI operation

Post by Yadnik » Mon Aug 09, 2021 1:31 pm

Thank you Robert,
The output I get is as follows:
>>> dir (machine)
['__name__', 'I2C', 'Pin', 'SPI', 'Signal', 'UART', 'idle', 'reset', 'reset_cause']

Post Reply