I'm trying to echo what I send via MOSI with MISO pin, so I just short circuited the MOSI and MISO pins. [url=Here is the code:
Code: Select all
int main(void) {
halInit();
chSysInit();
init_io();
// start the blinker thread
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
spiStart(&SPID1, &test_spicfg);
spiSelect(&SPID1);
uint8_t txbuffer[2];
uint8_t rxbuffer[2];
uint8_t offset = 0;
uint8_t num_zero = 48;
rxbuffer[1] = 0x33;
txbuffer[0] = 65; // A
while (true) {
chThdSleepMilliseconds(1); //// debugger
txbuffer[1] = num_zero + offset;
#if ! defined MOSI_MISO_CONNECTED
// will send: "A0", "A1", ...
spiSend(&SPID1, 2, &txbuffer);
#else
// will send: "A0", "01", "12", "23", ...
spiExchange(&SPID1, 2, &txbuffer, &rxbuffer);
txbuffer[0] = rxbuffer[1]; // debugger <--------------- this reads always {0, 0}
#endif
offset++;
if (offset > 9u) {
offset = 0;
}
}
Exact code is here.. SPI Config struct:
Code: Select all
SPIConfig test_spicfg = {
circular: false,
end_cb: NULL,
ssport: GPIOA,
cr1: (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_MSTR | SPI_CR1_BIDIOE),
cr2: (SPI_CR2_DATASIZE_8BIT)
};
Logic analyzer screenshot when I connected MISO to VDD:
Problem
The "rxbuffer" is always {0,0}. What am I possibly doing wrong?