Hi,
My Jetson agx orin is currently using JetPack_5.1.2,
When I was using spi2, there was a problem, spi2 communication failed, and the output data waveform could not be measured with the oscilloscope.
Let me explain how I do it:
1.Check whether the pinmux file is normal,
2.Check my “tegra234 - soc - spi.dtsi”, its path is “/ source/Linux_for_Tegra/source/public/hardware/nvidia/soc/t23x/kernel-dts/tegra234 - soc /”
3.Load driver
sudo devmem2 0x0c302048 word 0x00000400
sudo devmem2 0x0c302050 word 0x00000450
sudo devmem2 0x0c302048 word 0x00000400
sudo devmem2 0x0c302028 word 0x00000400
sudo modprobe spide
4.run code
#define SPI_DEVICE_PATH "/dev/spidev2.0"
#define SPI_SPEED_HZ 1000000 // 500kHz
void handleError(const char *msg)
{
perror(msg);
exit(EXIT_FAILURE);
}
void spiTest()
{
int spiDev = open(SPI_DEVICE_PATH, O_RDWR);
if (spiDev < 0)
{
handleError("Unable to open the SPI device");
}
uint8_t mode = SPI_MODE_0;
if (ioctl(spiDev, SPI_IOC_WR_MODE, &mode) < 0)
{
handleError("Unable to set the SPI mode");
}
uint32_t speed = SPI_SPEED_HZ;
if (ioctl(spiDev, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0)
{
handleError("Unable to set the SPI rate");
}
struct spi_ioc_transfer spi;
std::memset(&spi, 0, sizeof(spi));
uint8_t txData[] = {0xAA, 0xBB};
uint8_t rxData[sizeof(txData)];
spi.tx_buf = reinterpret_cast<unsigned long>(&txData);
spi.rx_buf = reinterpret_cast<unsigned long>(&rxData);
spi.len = sizeof(txData);
spi.delay_usecs = 0;
spi.speed_hz = speed;
spi.bits_per_word = 8;
while (true)
{
/* code */
if (ioctl(spiDev, SPI_IOC_MESSAGE(1), &spi) < 0)
{
handleError("SPI transfer failure");
}
printf("********Test SPIDEV2.0****** \n");
printf("Tx Data: 0x%02X 0x%02X\n", txData[0], txData[1]);
printf("Rx Data: 0x%02X 0x%02X\n", rxData[0], rxData[1]);
usleep(1000 * 1000 * 1);
}
printf("Rx Data: 0x%02X 0x%02X\n", rxData[0], rxData[1]);
close(spiDev);
}
When I used the SPI loopback test, it also didn’t work properly…