I read your post How to Use WiringPi on Edge. Your edge board running gpio readall can display the SPI pins with right Name like SPI3_CS/GPIO1_C2 and SPI3_CLK/GPIO1_C1.
But on my vim3 board gpio readall strangely displays the SPI pins of unclear Name like PIN.H4 and PIN.H6, PIN.H7 and PWM-F.
VIM3 SPI:
PIN37: GPIOH_4/SPIB_MOSI -> type ALT2
PIN35: PWM_F/SPIB_MISO -> type ALT2
PIN15: UARTC_RX/SPIB_SS -> type OUT
PIN16: UARTC_TX/SPIB_SCLK -> type ALT2
I met some build error running on my VIM3 and I had fixed it on my own.
My git diff shown as below just for your reference.
PS C:\Project\vim3\WiringPi_khadas\WiringPi> git diff
warning: LF will be replaced by CRLF in examples/Makefile.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in examples/spi_test_vim3.c.
The file will have its original line endings in your working directory
diff --git a/examples/Makefile b/examples/Makefile
index 6d87885..e7ef733 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -48,7 +48,8 @@ SRC = blink.c blink8.c blink12.c \
delayTest.c serialRead.c serialTest.c okLed.c ds1302.c \
lowPower.c \
max31855.c \
- rht03.c
+ rht03.c \
+ spi_test_vim3.c
OBJ = $(SRC:.c=.o)
@@ -61,6 +62,10 @@ all:
really-all: $(BINS)
+spi_test_vim3: spi_test_vim3.o
+ $Q echo [link]
+ $Q $(CC) -o $@ spi_test_vim3.o $(LDFLAGS) $(LDLIBS)
+
blink: blink.o
$Q echo [link]
$Q $(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS)
diff --git a/examples/spi_test_vim3.c b/examples/spi_test_vim3.c
index 25ba79c..713f908 100644
--- a/examples/spi_test_vim3.c
+++ b/examples/spi_test_vim3.c
@@ -12,16 +12,21 @@ int main()
printf("set up error");
exit(1);
}
+ printf("set up ok\n");
+
if(-1 == wiringPiSPISetup(0, 10000000)){
printf("set up spi error");
exit(-1);
}
- reg = wiringPiSPIDataRW_khadas(0, &data1, $data2, 1);
+ printf("set up spi ok\n");
+
+ reg = wiringPiSPIDataRW_khadas(0, &data1, &data2, 1);
if(reg < 0){
printf("RW error");
exit(-1);
}
+ printf("RW ok\n"); printf("data : %c\n\n", data2); exit(0); (END)
My SSH console on my VIM3 shown as below:
khadas@Khadas:~/workspace/WiringPi_khadas/examples$ make spi_test_vim3
[CC] spi_test_vim3.c
[link]
khadas@Khadas:~/workspace/WiringPi_khadas/examples$ ./spi_test_vim3
set up ok
set up spi ok
RW ok
data :
I have NOT connected my VIM3 with my sensor so currently no data receiced.
But the wiringPiSPIDataRW_khadas() return does NOT say any error so can I think of that my SPI on VIM3 works ?@Frank
I connected PIN37 and PIN35 which means I connected MOSI and MISO
This way is currently only choice for me to test SPI communication on my VIM3 because my sensor hasn’t arrived my home.
And I modified the examples/spi_test_vim3.c. based on khadas/WiringPi.
C:\GitRepo\cmou\Khadas_WiringPi>git diff
warning: LF will be replaced by CRLF in examples/spi_test_vim3.c.
The file will have its original line endings in your working directory
diff --git a/examples/spi_test_vim3.c b/examples/spi_test_vim3.c
index 713f908..23d8c22 100644
--- a/examples/spi_test_vim3.c
+++ b/examples/spi_test_vim3.c
@@ -2,10 +2,15 @@
#include <wiringPi.h>
#include <wiringPiSPI.h>
+#include <string.h>
+
int main()
{
- unsigned char data1 = 'a';
- unsigned char data2;
+ //unsigned char data1 = 'a';
+ //unsigned char data2;
+
+ unsigned char data1[8]= {0x12, 0x34, 0x56, 0x78};
+ unsigned char data2[8];
int reg;
if(-1 == wiringPiSetup()){
@@ -21,13 +26,15 @@ int main()
}
printf("set up spi ok\n");
- reg = wiringPiSPIDataRW_khadas(0, &data1, &data2, 1);
+ memset(data2, 0, 8);
+ reg = **wiringPiSPIDataRW_khadas(0, data1, data2, 4);**
if(reg < 0){
printf("RW error");
exit(-1);
}
printf("RW ok\n");
- printf("data : %c\n\n", data2);
+ printf("data1 : %x \n", *((unsigned int*)data1));
+ printf("data2 : %x \n", *((unsigned int*)data2));
exit(0);
}
Then I saw the communication works well :]
My SSH console shown as below:
khadas@Khadas:~/workspace/WiringPi_khadas/examples$ make spi_test_vim3
[CC] spi_test_vim3.c
[link]
khadas@Khadas:~/workspace/WiringPi_khadas/examples$ ./spi_test_vim3
set up ok
model == MODEL_KHADAS_VIM3
set up spi ok
RW ok
**data1** : 78563412
**data2** : 78563412
Thank you @Frank . Gratefully to have Khadas team support.
After 3 days waiting. I connect MAX6675 which is a temperature sensor using SPI with my VIM3.
And it works well. Now I’m happy :]
Hope my experience can help so that I share more details on MyGitHub.