Skip to content

Commit c622913

Browse files
author
Demo User
committed
rc spi testing
1 parent 683661e commit c622913

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

examples/src/rc_spi_loopback.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
#define SLAVE 0
1919

2020

21-
#define SLAVE_MODE SPI_SLAVE_MODE_AUTO
2221
#define BUS_MODE SPI_MODE_0
2322
#define SPI_SPEED 24000000
2423

2524
int main()
2625
{
2726
char* test_str = "Hello World";
2827
int bytes = strlen(test_str); // get number of bytes in test string
29-
uint8_t buf[bytes]; // read buffer
28+
uint8_t buf[32]; // read buffer
3029
int ret; // return value
3130

3231
printf("Make sure the MISO and MOSI lines are connected with\n");
@@ -38,13 +37,26 @@ int main()
3837

3938
// attempt a string send/receive test
4039
printf("Sending %d bytes: %s\n", bytes, test_str);
41-
ret = rc_spi_transfer(BUS, SLAVE, (uint8_t*)test_str, bytes, buf);
42-
if(ret<0){
43-
printf("send failed\n");
44-
rc_spi_close(SLAVE);
45-
return -1;
40+
41+
while(1){
42+
//ret = rc_spi_transfer(BUS, SLAVE, (uint8_t*)test_str, bytes, buf);
43+
ret = rc_spi_write(BUS, SLAVE, (uint8_t*)test_str, bytes);
44+
if(ret<0){
45+
printf("send failed\n");
46+
rc_spi_close(SLAVE);
47+
return -1;
48+
}
49+
else printf("sent %d bytes: %s\n",bytes, test_str);
50+
// read back
51+
ret = rc_spi_read(BUS, SLAVE, buf, bytes);
52+
if(ret<0){
53+
printf("read failed\n");
54+
rc_spi_close(SLAVE);
55+
return -1;
56+
}
57+
else printf("Received %d bytes: %s\n",ret, (char*)buf);
58+
rc_usleep(10000);
4659
}
47-
else printf("Received %d bytes: %s\n",ret, buf);
4860

4961
rc_spi_close(BUS);
5062
return 0;

library/include/rc/spi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
* RC_SPI_MAX_SPEED, RC_BLUE_SS1_GPIO);
2222
* ```
2323
*
24+
* pinout on Robotics Cape and BeagleBone Blue:
25+
* 1. GND
26+
* 2. 3.3V
27+
* 3. MOSI (P9_30)
28+
* 4. MISO (P9_29)
29+
* 5. SCK (P9_31)
30+
* 6. Slave Select
31+
*
32+
*
2433
* The slaves can be selected automatically by the SPI Linux driver or manually
2534
* with rc_spi_select() function. On the Robotics Cape, slave 1 can be used in
2635
* either mode, but slave 2 must be selected manually. On the BB Blue either

library/src/io/spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ int rc_spi_init_manual_slave(int bus, int slave, int bus_mode, int speed_hz, int
272272
state[bus].init[slave] = 1;
273273
state[bus].ss_mode[slave] = SS_MODE_MANUAL;
274274
state[bus].chip[slave] = chip;
275-
state[bus].pin[slave] = chip;
275+
state[bus].pin[slave] = pin;
276276
state[bus].fd[slave] = fd;
277277
state[bus].fd[0] = fd; // just in case we are initializing a slave other than 0 first
278278
state[bus].speed[slave] = speed_hz;

0 commit comments

Comments
 (0)