I am using torizon imx7d for running spi in python but i am getting fixed value
I did steps:
1)when i run # docker run --rm -it -v /dev:/dev --device-cgroup-rule=‘c 254:* rmw’ torizonextras/arm32v7-gpiod and did gpioinfo I found SODIMM_63 is line 2 on gpiochip6.
2)# docker run --rm -it --device /dev/gpiochip6 --device .dev/spidev2.0 intersense123/spi_app.
3)my dts file is
intersense@Lenovo:~$ cat colibri-imx7_spidev_overlay.dts
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/*
- Copyright 2022 Toradex
*/
// Colibri imx7 spidev
/dts-v1/;
/plugin/;
/ {
compatible = “toradex,colibri-imx7d”,
“toradex,colibri-imx7d-emmc”,
“toradex,colibri-imx7s”;
};
/* Colibri SPI */
&ecspi3 {
#address-cells = <1>;
#size-cells = <0>;
status = “okay”;
spidev@0 {
/* Use compatible "rohm,dh2228fv" to bind spidev driver */
compatible = "rohm,dh2228fv";
reg = <0>;
spi-max-frequency = <10000000>;
};
};
is there any need to change in dts file or anywhere.
4)this is my main.py:
import spidev
import gpiod
import time
=== SPI SETUP ===
spi = spidev.SpiDev()
spi.open(2, 0) # Bus 2, CS 0 (We’ll manually control CS)
spi.max_speed_hz = 10 * 1000 * 1000
spi.mode = 0 # SpiMode 0
spi.bits_per_word = 16 # PackedMode = 1 equivalent
=== GPIO SETUP for manual CS ===
chip = gpiod.Chip(“gpiochip6”) # Assuming SODIMM 63 is on gpiochip6
cs_line = chip.get_line(2) # SODIMM 63 is gpiochip6 line 2
config = gpiod.LineRequest()
config.consumer = “spi-cs”
config.request_type = gpiod.LINE_REQ_DIR_OUT
cs_line.request(config)
=== SPI transfer buffers ===
spiData_Range = [0xD414, 0x0001]
rxBuffer =
while True:
count = 0
sum_1 = 0
for _ in range(20):
cs_line.set_value(0) # CS low (active)
time.sleep(0.01) # Sleep 10 ms
# Transfer (send spiData_Range and read response)
response = spi.xfer2(spiData_Range)
cs_line.set_value(1) # CS high (inactive)
num_1 = response[0] # Only first word received
sum_1 += num_1
count += 1
avg = sum_1 // count if count > 0 else 0
print(f"rxBuffer_1[0] = {avg}")
time.sleep(0.1) # Sleep 100ms (optional)
Cleanup (you can use try/finally in real code)
spi.close()
cs_line.release()
5)i am getting output :[69, 0, 0, 0]
[69, 0, 0, 0]
[69, 0, 0, 0]
[69, 0, 0, 0]
[69, 0, 0, 0]
[69, 0, 0, 0]
[69, 0, 0, 0]
[69, 0, 0, 0]
[69, 0, 0, 0]
[69, 0, 0, 0]
please guide me for setup and all @ToradexAI