Run gpio readall does not display right Name for SPI pins

Hi @goenjoy, @Frank and @numbqq,

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.

And spidev1.0 exists is under /dev. I modified device tree overlay and kvim3_linux.dts based on this post VIM3 GPIO "WiringPI" SPI - #24 by ChiaHungMou.

I flash my vim3 board by the image built based on the newest fenix commit.

My gpio readall shown as below:

`	khadas@Khadas:~$ gpio readall
 +------+-----+----------+------+---+----+---- Model  Khadas VIM3 --+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 |      |     |       5V |      |   |    |       |  1 || 21 |       |    |   |      | GND      |     |      |
 |      |     |       5V |      |   |    |       |  2 || 22 | P/U   |    | 1 | ALT1 | PIN.A15  | 6   |  475 |
 |      |     |   USB_DM |      |   |    |       |  3 || 23 | P/U   |    | 1 | ALT1 | PIN.A14  | 7   |  474 |
 |      |     |   USB_DP |      |   |    |       |  4 || 24 |       |    |   |      | GND      |     |      |
 |      |     |      GND |      |   |    |       |  5 || 25 | P/U   |    | 1 | ALT0 | PIN.AO2  | 8   |  498 |
 |      |     |   MCU3V3 |      |   |    |       |  6 || 26 | P/U   |    | 1 | ALT0 | PIN.AO3  | 9   |  499 |
 |      |     |  MCUNRST |      |   |    |       |  7 || 27 |       |    |   |      | 3V3      |     |      |
 |      |     |  MCUSWIM |      |   |    |       |  8 || 28 |       |    |   |      | GND      |     |      |
 |      |     |      GND |      |   |    |       |  9 || 29 | P/D   |    | 0 | ALT0 | PIN.A1   | 10  |  461 |
 |      |  18 |     ADC0 |      |   |    |       | 10 || 30 | P/D   |    | 1 | ALT0 | PIN.A0   | 11  |  460 |
 |      |     |      1V8 |      |   |    |       | 11 || 31 | P/D   |    | 0 | ALT0 | PIN.A3   | 12  |  463 |
 |      |  19 |     ADC1 |      |   |    |       | 12 || 32 | P/D   |    | 0 | ALT0 | PIN.A2   | 13  |  462 |
 |  506 |   1 | PIN.AO10 | ALT3 | 0 |    |   P/U | 13 || 33 | P/D   |    | 0 | ALT1 | PIN.A4   | 14  |  464 |
 |      |     |     GND3 |      |   |    |       | 14 || 34 |       |    |   |      | GND      |     |      |
 |  433 |   2 |   PIN.H6 |  OUT | 1 |    |   P/D | 15 || 35 | P/D   |    | 0 | ALT2 | PWM-F    | 15  |  432 |
 |  434 |   3 |   PIN.H7 | ALT2 | 0 |    |   P/D | 16 || 36 |       |    |   |      | RTC      |     |      |
 |      |     |      GND |      |   |    |       | 17 || 37 | P/D   |    | 0 | ALT2 | PIN.H4   | 16  |  431 |
 |  497 |   4 |  PIN.AO1 | ALT0 | 1 |    |   P/U | 18 || 38 |       |    |   |      | MCU-FA1  |     |      |
 |  496 |   5 |  PIN.AO0 | ALT0 | 1 |    |   P/U | 19 || 39 | P/D   |    | 0 | IN   | PIN.Z15  | 17  |  426 |
 |      |     |      3V3 |      |   |    |       | 20 || 40 |       |    |   |      | GND      |     |      |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+

 `

Pins related to SPI.

   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

Thank you very much.

1 Like

@ChiaHungMou Please check it with A311D datasheet . for examlple

Thsi is GPIOH4

When it use for SPI , it’s ALT2 . . .

2 Likes

Thank you @Frank .Your reply raised my morale to move forward.

Just forked the GitHub - khadas/WiringPi: WiringPi for Khadas boards and got noticed that gratefully Khadas team provide us a particular API wiringPiSPIDataRW_khadas() when we employ WiringPi.

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

Thanks always.

1 Like

Hi @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

My VIM3 connected MOSI and MISO shown as below:

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.

MAX6675 reading temperature on Khadas VIM3:

2 Likes