Closed Amir7RN closed 11 months ago
just changed the spi-mode in "esc_hw.c" line 478 to mode 3:
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); --->
bcm2835_spi_setDataMode(BCM2835_SPI_MODE3);
and updated the code and utilizing bcm2835_spi_transfernb rather bcm2835_spi_transfer:
int16_t received_data = 0;
int16_t SPI_transmit_int(int data)
{
int16_t spi_data[2];
spi_data[0] = ESC_CMD_SERIAL_WRITE;
spi_data[1] = (int16_t)(((data >> 8) & 0xFF));
spi_data[2] = (int16_t)(data & 0xFF);
bcm2835_spi_transfernb((char*)spi_data, (char*)spi_data, sizeof(spi_data));
usleep(10);
spi_data[0] = ESC_CMD_SERIAL_READ;
bcm2835_spi_transfernb((char*)spi_data, (char*)spi_data, sizeof(spi_data));
int16_t received_data_unit = (int16_t)(((int32_t)spi_data[1] << 8) | (int32_t)spi_data[2]);
received_data = received_data_unit;
return received_data;
}
resolved my problem.
Ok, good that it works.
I can’t find what mode or how to change it for LAN9252, have you?
For ET1100 it is an EEPROM setting.
Close as fixed
I am encountering an issue with the SPI transmission in my code, and I would appreciate your guidance in resolving it. I am using a Raspberry Pi 4 and EVB-lan9252 in my setup.
I have noticed that the transmitted value via SPI is inconsistent. To isolate the issue, I simplified the code here and assigned a constant float value of 0.055f to a variable named "pitch." I intended to monitor the transmitted pitch value via SPI, expecting it to remain at a fixed value of 0.055f (which will be transmitted as a "55" integer). However, even in this simplified scenario, I still observe sudden jumps and peaks in the transmitted pitch value.
It's important to note that the pitch value is a float when assigned in the code, but it is received by SPI as an integer.
I have included the simplified code below:
here is the output of SPI: it is constant 55 but there sudden peaks and jumps: