midv
September 9, 2022, 1:46pm
1
Hello.
I am trying to set up communication between stm32 and jetson. Jetson is in slave mode.
I set up jetson to receive data from stm32 and I receive data in jetson.
But I can’t send data from jetson.
How can I do it?
I modified spidev_test.c
in this case I get data
static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
{
int ret;
int out_fd;
struct spi_ioc_transfer tr = {
.tx_buf = 0,//(unsigned long)tx,
.rx_buf = (unsigned long)rx,
.len = 30,
.delay_usecs = 1000,
.speed_hz = 328125,
.bits_per_word = bits,
};
if (mode & SPI_TX_QUAD)
tr.tx_nbits = 4;
else if (mode & SPI_TX_DUAL)
tr.tx_nbits = 2;
if (mode & SPI_RX_QUAD)
tr.rx_nbits = 4;
else if (mode & SPI_RX_DUAL)
tr.rx_nbits = 2;
if (!(mode & SPI_LOOP)) {
if (mode & (SPI_TX_QUAD | SPI_TX_DUAL))
tr.rx_buf = 0;
else if (mode & (SPI_RX_QUAD | SPI_RX_DUAL))
tr.tx_buf = 0;
}
for (int i = 10; i > 0;){
usleep(1);
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
if (ret < 0)
continue;
i--;
printf("ret = %d ", ret);
hex_dump(rx, len, ret, "RX");
}
}
but if I uncommited line
.tx_buf = (unsigned long)tx,
program is waiting
Moving this topic to the Jetson Nano category.
Have reference to below topic. Also confirm if modify device tree to enable Nano SPI as slave mode.
I have two Jetson Nano devices that need to exchange data over SPI protocol. It is my first and only project with Jetson Nano, so I am completely new to the SPI or anything regarding low-level coding.
In the project, I want to use Daisy Chain to communicate, for starters I have used only two devices to test the data communication between them.
Using the following link on page 4, I made one a slave. https://www.nxp.com/files-static/training_pdf/26821_68HC08_SPI_WBT.pdf
What it says is that in …
midv
September 12, 2022, 5:33am
5
Hi, ShaneCCC.
Yes, I modified device tree.
I send packet (30 bytes) from STM32 in master mode and receive this packet (30 bytes) in nano.
But when I try send some data (30 bytes) from nano to STM32 - I can’t
midv
September 12, 2022, 6:48am
6
I configured spidev1 as slave and spidev0 as master.
I connected
24<->18 (CS0)
13<->23 (SCK)
22<->21 (Din)
19<->37 (Dout)
sudo ./spidev_test -D /dev/spidev0.0 -s 100000 -p4 -n1 -g30 -zzz
using device: /dev/spidev0.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 100000 Hz (100 KHz)
no. runs: 1
Using seed:0x631ed54a
loop count = 0
Using rand() buffer
Using crc check
transfer packet bytes [30]
0000: FE EE CA AB 68 83 DF 7B 00 00 12 00 75 84 4A 18
0010: 69 38 9E C1 F7 88 CF E2 C7 2F 0A 2D 23 8B
transfer: Return actual transfer length: 30
receive packet bytes [30]
0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
transfer: received packet size:30 len:0 stat:-6
transfer: received packet size:29 len:0 stat:-6
transfer: received packet size:28 len:0 stat:-6
transfer: received packet size:27 len:0 stat:-6
transfer: received packet size:26 len:0 stat:-6
transfer: received packet size:25 len:0 stat:-6
transfer: received packet size:24 len:0 stat:-6
transfer: received packet size:23 len:0 stat:-6
transfer: received packet size:22 len:0 stat:-6
transfer: received packet size:21 len:0 stat:-6
transfer: received packet size:20 len:0 stat:-6
transfer: received packet size:19 len:0 stat:-6
transfer: received packet size:18 len:0 stat:-6
transfer: received packet size:17 len:0 stat:-6
transfer: received packet size:16 len:0 stat:-6
transfer: received packet size:15 len:0 stat:-6
transfer: received packet size:14 len:0 stat:-6
transfer: received packet size:13 len:0 stat:-6
transfer: received packet size:12 len:0 stat:-6
/dev/spidev0.0: TEST FAILED !!!!! (status:-1)
====== Transfer stats ====
Transmit:
total: 30B (0KiB 0MiB)
total: 1P
ioerr: 0B (0KiB 0MiB)
ioerr: 0P
Rate:
wire total: -1B/s (0KB/s)
total: -1B/s (0KB/s)
wire total: -1P/s
total: -1P/s
Receive:
total: 30B (0KiB 0MiB)
total: 0P
good: 0B (0KiB 0MiB)
good: 0P
ioerr: 0P
dataerr: 0P
Rate:
good: -1B/s (0KB/s)
good: -1P/s
packet drop: -1/10000
Total time: 0.003766s
sudo ./spidev_test -D /dev/spidev1.0 -s 100000 -p4 -n1 -g30 -zzz -r
Disabling transmit
using device: /dev/spidev1.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 100000 Hz (100 KHz)
no. runs: 1
Using seed:0x631ed547
loop count = 0
transfer: Return actual transfer length: 30
receive packet bytes [30]
0000: FE EE CA AB 68 83 DF 7B 00 00 12 00 75 84 4A 18
0010: 69 38 9E C1 F7 88 CF E2 C7 2F 0A 2D 23 8B
transfer: received packet size:30 len:18 stat:0
/dev/spidev1.0: TEST PASSED
====== Transfer stats ====
Receive:
total: 30B (0KiB 0MiB)
total: 1P
good: 30B (0KiB 0MiB)
good: 1P
ioerr: 0P
dataerr: 0P
Rate:
good: 11B/s (0KB/s)
good: 0P/s
packet drop: -1/10000
Total time: 2.722988s
How can I check the transmission from slave to master?
Why configure as master mode to transfer data from Nano?
midv
September 12, 2022, 8:32am
9
I wanted to show the output. In the future, the master mode on the nano will not be used.