Hallo,
Ich habe 2 SPI Slaves am Raspberry Pi 3 Model B. Die CS-Pins haben
jeweils einen Pullup Widerstand. Das eine Slave funktioniert, das andere
ist der FXOS8700CQ Beschleunigungs- und Magnetfeldsensor und antwortet
nicht.
Im Datenblatt https://www.nxp.com/docs/en/data-sheet/FXOS8700CQ.pdf
Kapitel 10.2.3 steht, dass der SA0/MISO Pin beim Einschalten hochohmig
sein muss, um den SPI-Modus zu aktivieren. Nach meinem Wissen und
Verständnis sollten die GPIO's inklusive der SPI Pins beim Einschalten
hochohmig sein.
Ich könnte mir vorstellen, dass der Fehler darin liegt, dass ich das
Kapitel 10.2.2 SPI read/write operations falsch verstanden habe: Das
zweite Byte in Fig. 8 besteht aus ADDR[7] und 7 don't care bits. Da aber
die größte Adresse 0x79 ist, würde das zweite Byte immer eine 0 mit 7
don't care bits sein... klingt irgendwie falsch.
Als Test soll die Device ID ausgegeben werden.
1 | #include <stdio.h>
|
2 | #include <fcntl.h>
|
3 | #include <sys/ioctl.h>
|
4 | #include <linux/spi/spidev.h>
|
5 | #include <inttypes.h>
|
6 | #include <stdlib.h>
|
7 | #include <stdint.h>
|
8 | #include <errno.h>
|
9 | #include <string.h>
|
10 | #include <asm/ioctl.h>
|
11 | #include <wiringPiSPI.h>
|
12 | #include <linux/spi/spidev.h>
|
13 | #include "wiringPi.h"
|
14 |
|
15 |
|
16 | int main()
|
17 | {
|
18 | unsigned char buffer [32];
|
19 | int i =0;
|
20 | wiringPiSetup();
|
21 | if(wiringPiSPISetup(0, 500000)==-1) // fd=0: FXOS
|
22 | {
|
23 | printf("Could not initialise SPI\n");
|
24 | return 0;
|
25 | }
|
26 |
|
27 | // Read device id (0x0D)
|
28 | buffer[0]=0x0d;
|
29 | buffer[1]=0;
|
30 | buffer[2]=0;
|
31 |
|
32 | wiringPiSPIDataRW(0, buffer, 3);
|
33 |
|
34 | printf("Device ID: %x\n", ((char*)buffer)[2]);
|
35 | for(i=0;i<3;i++)
|
36 | {
|
37 | printf("%x ", ((char*)buffer)[i]);
|
38 | }
|
39 |
|
40 | return 0;
|
41 | }
|
Es kommen aber leider nur Nullen zurück. Erkennt jemand einen Fehler?
Vielen Dank im Voraus!