Ich bin seit mehreren Tagen daran, über einen STM32L151 (Master) mit
einem Funkmodul (Slave) per SPI zu kommunizieren. Mit einem Oszi konnte
ich bereits sicherstellen, dass die Kommunikation standardgemäß abläuft.
CS, CLK, MOSI und MISO werden von dem STM32 und der Gegenstelle
(scheinbar) korrekt angesteuert.
Das einzige Problem ist, dass ich beim Empfangen ausschließlich 0
erhalte, obwohl das Funkmodul die richtigen Datenbits auf MISO gibt. Ich
habe den Chip bereits erfolglos ausgetauscht.
Hier ist die Initialisierungsroutine:
SPI sendet und empfängt gleichzeitig. Ohne dem code für Ablauf, ist es
schwer raus zufinden, was du machst (Stichwort minimalcode).
Aber wenn du das DR beschreibst und liest, dann ist es null. Les das DR
mal vorher aus und du solltest nach dem Beschreiben des DR registers
auch den SPI Transfer starten, sonst ist da nix drinnen.
SPI1->DR = 0x00;
uint8_t recv = SPI1->DR;
Danke für die Tipps. So wie ich das verstanden habe, wird durch das
Schreiben in das DR Register bereits das Senden gestartet, siehe
Refrence Manual:
>– The sequence begins when data are written into the SPI_DR register (Tx buffer).>– The data are then parallel loaded from the Tx buffer into the 8-bit shift
register
>during the first bit transmission and then shifted out serially to the MOSI pin.>– At the same time, the received data on the MISO pin is shifted in serially to
the 8-
>bit shift register and then parallel loaded into the SPI_DR register (Rx buffer).
Was passiert, wenn du nach SPI1->DR = 0x00; einfach manuell 200ms
wartest und dann liest. Dann würde deine Flag Abfrage nicht greifen oder
die falsche sein oder muss negiert werden.