Added check for SPI communication with radio module

This commit is contained in:
Wolfgang Klenk 2017-04-14 19:10:45 +02:00
parent 5f7b457fcc
commit da68f8111d
2 changed files with 33 additions and 1 deletions

View File

@ -36,7 +36,8 @@ Directory: /examples/hello
Modifications necessary: None Modifications necessary: None
This example does not use radio, it just periodically logs a counter value. This example does not use radio, it just periodically logs a counter value.
Can be used to checked if the timer implementation on RPi works as expected. Can be used to checked if the timer implementation on RPi works as expected
and if SPI communication with the radio board is possible.
cd examples/hello cd examples/hello
make clean make clean
@ -46,6 +47,7 @@ Can be used to checked if the timer implementation on RPi works as expected.
Possible output: Possible output:
000000000 HAL: Initializing ... 000000000 HAL: Initializing ...
000000003 HAL: Detected SX1276 radio module.
000000003 HAL: Set radio RST pin to 0x00 000000003 HAL: Set radio RST pin to 0x00
000000003 HAL: Wait until 000000004 ms 000000003 HAL: Wait until 000000004 ms
000000005 HAL: Set radio RST pin to 0x02 000000005 HAL: Set radio RST pin to 0x02
@ -109,6 +111,7 @@ work with a Single Channel Gateway.
Possible outpout: Possible outpout:
000000000 HAL: Initializing ... 000000000 HAL: Initializing ...
000000000 HAL: Detected SX1276 radio module.
000000001 HAL: Set radio RST pin to 0x00 000000001 HAL: Set radio RST pin to 0x00
000000002 HAL: Wait until 000000002 ms 000000002 HAL: Wait until 000000002 ms
000000003 HAL: Set radio RST pin to 0x02 000000003 HAL: Set radio RST pin to 0x02
@ -152,6 +155,7 @@ every 60 seconds as an unconfirmed message with a payload of 2 bytes.
Possible output: Possible output:
000000000 HAL: Initializing ... 000000000 HAL: Initializing ...
000000004 HAL: Detected SX1276 radio module.
000000004 HAL: Set radio RST pin to 0x00 000000004 HAL: Set radio RST pin to 0x00
000000005 HAL: Wait until 000000006 ms 000000005 HAL: Wait until 000000006 ms
000000006 HAL: Set radio RST pin to 0x02 000000006 HAL: Set radio RST pin to 0x02

View File

@ -98,6 +98,34 @@ void hal_init () {
hal_failed(); hal_failed();
} }
// Make sure that SPI communication with the radio module works
// by reading the "version" register 0x42 of the radio module.
hal_pin_nss(0);
hal_spi(0x42 & 0x7F);
u1_t val = hal_spi(0x00);
hal_pin_nss(1);
if (0 == val) {
fprintf(stderr, "HAL: There is an issue with the SPI communication to the radio module.\n");
fprintf(stderr, "HAL: Make sure that \n");
fprintf(stderr, "HAL: * The radio module is attached to your Raspberry Pi\n");
fprintf(stderr, "HAL: * The power supply provides enough power\n");
fprintf(stderr, "HAL: * SPI is enabled on your Raspberry Pi. Use the tool \"raspi-config\" to enable it.\n");
hal_failed();
}
#ifdef DEBUG_HAL
if (0x12 == val) {
fprintf(stdout, "%09d HAL: Detected SX1276 radio module.\n", osticks2ms(hal_ticks()));
}
else if (0x22 == val) {
fprintf(stdout, "%09d HAL: Detected SX1272 radio module.\n", osticks2ms(hal_ticks()));
}
else {
fprintf(stdout, "%09d HAL: Detected unknown radio module: 0x%02x\n", osticks2ms(hal_ticks()), val);
}
#endif
} }
void hal_failed () { void hal_failed () {