iitm sat
/
Beacon_test_code
TESTING CONNECTIONS IN BCN
main.cpp@0:2211888e98cf, 2016-04-13 (annotated)
- Committer:
- spacelab
- Date:
- Wed Apr 13 16:38:24 2016 +0000
- Revision:
- 0:2211888e98cf
TESTING spi CONNECTIONS FOR BCN;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
spacelab | 0:2211888e98cf | 1 | #include "mbed.h" |
spacelab | 0:2211888e98cf | 2 | Serial pc(USBTX, USBRX); // tx, rx |
spacelab | 0:2211888e98cf | 3 | //SPI spi(D11, D12, D13); // mosi, miso, sclk |
spacelab | 0:2211888e98cf | 4 | //DigitalOut cs(D10); //slave select or chip select |
spacelab | 0:2211888e98cf | 5 | SPI spi(PTE18, PTE19, PTE17); // mosi, miso, sclk |
spacelab | 0:2211888e98cf | 6 | DigitalOut cs(PTE5); //slave select or chip select |
spacelab | 0:2211888e98cf | 7 | #define RF22_REG_00_DEVICE_TYPE 0x00 |
spacelab | 0:2211888e98cf | 8 | |
spacelab | 0:2211888e98cf | 9 | uint8_t readreg(uint8_t reg) |
spacelab | 0:2211888e98cf | 10 | { |
spacelab | 0:2211888e98cf | 11 | int val;cs = 0;__disable_irq();spi.write(reg & ~0x80);val = spi.write(0);__enable_irq();cs = 1;return val; |
spacelab | 0:2211888e98cf | 12 | } |
spacelab | 0:2211888e98cf | 13 | int main() |
spacelab | 0:2211888e98cf | 14 | { |
spacelab | 0:2211888e98cf | 15 | wait(1); // wait for POR to complete //change the timing later |
spacelab | 0:2211888e98cf | 16 | cs=1; // chip must be deselected |
spacelab | 0:2211888e98cf | 17 | wait(1); //change the time later |
spacelab | 0:2211888e98cf | 18 | spi.format(8,0); |
spacelab | 0:2211888e98cf | 19 | spi.frequency(10000000); //10MHz SCLK |
spacelab | 0:2211888e98cf | 20 | if (readreg(RF22_REG_00_DEVICE_TYPE) == 0x08) pc.printf("spi connection valid\n"); |
spacelab | 0:2211888e98cf | 21 | else pc.printf("error in spi connection\n"); |
spacelab | 0:2211888e98cf | 22 | } |