Jump to content

problems with spidev on orange pi lite 2


Teslacreiste

Recommended Posts

I bought an orange pi lite 2 and I would like to use it with the ADC MCP3008 but when executing the code in python using the spidev library, it always returns the value of 1023 and when I disconnect the ADC it keeps showing the same value, it is as if there was no communication , The ADC is not the one with the problem since I tried it with an arduino mega and it works perfectly, it is in the orange pi lite 2 where it does not work.

 

the connections are:

VDD=3.3V

VREF=3.3V

AGND=GND

CLK= (PC00) SPIO_CLK

DOUT=(PC03) MISO

DINT=(PC02) MOSI

CS = (PC05) SPI0_CS0

DGND= GND

 

import spidev
import time

spi = spidev.SpiDev()
spi.open(0, 0)

def read()
	adc = spi.xfer2([1,8<<4,0])
	data = ((adc[1] & 3) << 8) + adc[2]
	return data

while True:
	print(====================)
	print(read())
	time.sleep(0.5)

 

The only thing that returns is 1023 always

 

if I have the spidev0.0

 

my armbianEnv.txt

 

verbosity=1
bootlogo=false
console=both
disp_mode=1920x1080p60
overlay_prefix=sun50i-h6
rootdev=UUID=07e078d5-15c7-4e03-8ec7-edf62ab350ed
rootfstype=ext4
overlays=spi-spidev w1-gpio
param_spidev_spi_bus=0
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

 

check the connection more than once, I don't know if the pins of MOSI, MISO, CLK and CS0; They are well configured with the ADC, I support myself for the connection with the following image.

 

51agTZrPICL._AC_SX425_.jpg

 

I speak Spanish, so I used google translator, therefore I apologize if I do not explain myself well.

Link to comment
Share on other sites

I have tried everything I realized that the cs0 pin, which is the PC05 pin, only stays high as long as the clock, the PC00 pin gives a pulse every time the Read () function is called, the clock should not be a Independent frequency to the calls of Read (), example if it is time.sleep (1) the PC00 pin of the clock will be 1Hz and if I decrease it will increase, this behavior should not be that of cs0?

 

root@orangepilite2:~# dmesg | grep spi
[    2.067074] sun6i-spi 5010000.spi: there is not valid maps for state default
[    2.067129] sun50i-h6-pinctrl 300b000.pinctrl: pin-64 (5010000.spi) status -517
[    2.067141] sun6i-spi 5010000.spi: Error applying setting, reverse things back
[    2.179882] sun6i-spi 5010000.spi: there is not valid maps for state default
[    2.179919] sun50i-h6-pinctrl 300b000.pinctrl: pin-64 (5010000.spi) status -517
[    2.179931] sun6i-spi 5010000.spi: Error applying setting, reverse things back
[    2.182803] sun6i-spi 5010000.spi: there is not valid maps for state default
[    2.182840] sun50i-h6-pinctrl 300b000.pinctrl: pin-64 (5010000.spi) status -517
[    2.182851] sun6i-spi 5010000.spi: Error applying setting, reverse things back
[    2.557945] sun6i-spi 5010000.spi: there is not valid maps for state default
[    2.557996] sun50i-h6-pinctrl 300b000.pinctrl: pin-64 (5010000.spi) status -517
[    2.558008] sun6i-spi 5010000.spi: Error applying setting, reverse things back
[    2.582175] sun6i-spi 5010000.spi: there is not valid maps for state default
[    4.840175] spidev spi0.0: probing from DT

set again the armbianEnv.txt

verbosity=1
bootlogo=false
console=both
disp_mode=1920x1080p60
overlay_prefix=sun50i-h6
rootdev=UUID=07e078d5-15c7-4e03-8ec7-edf62ab350ed
rootfstype=ext4
overlays=spi-add-cs1 spi-spidev
param_spidev_spi_bus=0
param_spidev_spi_cs=0
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

and the code I have changed

import spidev
import time

spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1000000


def Read():
        adc = spi.xfer2([1,8<<4,0])
        data = ((adc[1] & 3) << 8) + adc[2]
        return data

while True:
        print Read()
        time.sleep(0.08)

something funny is that if I disconnect the cs0 pin of the MCP3008 it starts receiving data sometimes.

the sun50i-h6-spi-spidev.dts

/dts-v1/;

/ {
	compatible = "allwinner,sun50i-h6";

	fragment@0 {
		target-path = "/aliases";
		__overlay__ {
			spi0 = "/soc/spi@5010000";
			spi1 = "/soc/spi@5011000";
		};
	};

	fragment@1 {
		target = <0xffffffff>;
		__overlay__ {
			#address-cells = <0x1>;
			#size-cells = <0x0>;
			spidev {
				compatible = "spidev";
				status = "disabled";
				reg = <0x0>;
				spi-max-frequency = <0xf4240>;
			};
		};
	};

	fragment@2 {
		target = <0xffffffff>;
		__overlay__ {
			#address-cells = <0x1>;
			#size-cells = <0x0>;
			spidev {
				compatible = "spidev";
				status = "disabled";
				reg = <0x0>;
				spi-max-frequency = <0xf4240>;
			};
		};
	};
    __fixups__ {
          	spi0 = "/fragment@1:target:0";
    		spi1 = "/fragment@2:target:0";
    };
};
};

I don't know what to do anymore, I need help (._.)

Link to comment
Share on other sites

Solve the problem by downloading an outdated version of armbian, armbian 20.05.4, it seems that the last version of armbian 20.08.1 works badly, when restarting it freezes and also the pin CS0 and CS1 are not activated, generating the communication problem by SPI, since the other pins are activated.

Anyway I hope someone will be of help to my solution, because it cost me time because I am a novice at this.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines