May 2021 Tests
Dependencies: SX127x sx12xx_hal
Revision 2:cfd70a2fb81f, committed 2021-05-09
- Comitter:
- lightshow
- Date:
- Sun May 09 20:03:44 2021 +0000
- Parent:
- 1:b277f5a65c1c
- Commit message:
- May 2021 Tests
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed_app.json | Show annotated file Show diff for this revision Revisions of this file |
diff -r b277f5a65c1c -r cfd70a2fb81f main.cpp --- a/main.cpp Thu Mar 21 10:22:46 2019 +0000 +++ b/main.cpp Sun May 09 20:03:44 2021 +0000 @@ -1,12 +1,62 @@ #include "radio.h" +//InterruptIn txByte[8]={InterruptIn(D2),InterruptIn(D3),InterruptIn(D4),InterruptIn(D5),InterruptIn(D7),InterruptIn(D8),InterruptIn(D9),InterruptIn(D14)}; +InterruptIn txByte0(PB_1);//D2,A1,PC_8 didn't work, PC_5 +InterruptIn txByte1(PB_15);//D3 didn't work, A2 works +InterruptIn txByte2(D4); +InterruptIn txByte3(D7); +InterruptIn txByte4(D5); +InterruptIn txByte5(PB_14);//D8 didn't work, a3 works +InterruptIn txByte6(D9);//D9 didn't work, a4 works +InterruptIn txByte7(D14);//D14,PC_0(A6),PC_6 didn't work +EventQueue queue(10 * EVENTS_EVENT_SIZE); +Thread t; +Radio loRaRadio; + +void transmit( uint8_t byte); + +//uint8_t old_byte = 0; +void tx_event(void) +{ + printf("tx_event\n\r"); + uint8_t byte = 0; + + uint8_t bit0 = txByte0.read(); + uint8_t bit1 = txByte1.read() << 1; + uint8_t bit2 = txByte2.read() << 2; + uint8_t bit3 = txByte3.read() << 3; + uint8_t bit4 = txByte4.read() << 4; + uint8_t bit5 = txByte5.read() << 5; + uint8_t bit6 = txByte6.read() << 6; + uint8_t bit7 = txByte7.read() << 7; + if(bit0 || bit1 || bit2 || bit3 || bit4 || bit5 || bit6 || bit7) + { + byte = bit0 + bit1 + bit2 + bit3 + bit4 + bit5 + bit6 + bit7; + transmit(byte); + } + printf("bit0 :%d,\n\r",bit0); + printf("bit1 :%d,\n\r",bit1); + printf("bit2 :%d,\n\r",bit2); + printf("bit3 :%d,\n\r",bit3); + printf("bit4 :%d,\n\r",bit4); + printf("bit5 :%d,\n\r",bit5); + printf("bit6 :%d,\n\r",bit6); + printf("bit7 :%d,\n\r",bit7); +} + +void rise_handler(void) { + //printf("rise_handler in context %p\r\n", Thread::gettid()); + queue.call(tx_event); + +} + // Semtech radio definitions for SX127x, SX126x and SX128x #if defined(SX127x_H) #define BW_KHZ 500 #define SPREADING_FACTOR 11 #define CF_HZ 912000000 - #define TX_DBM 20 + #define TX_DBM 00 #elif defined(SX126x_H) #define BW_KHZ 500 #define SPREADING_FACTOR 10 @@ -49,46 +99,78 @@ int main() { + // Start the event queue + t.start(callback(&queue, &EventQueue::dispatch_forever)); + + // The 'rise' handler will execute in the context of thread 't' + // for(int i = 0; i < 8; i++) + // { + // txByte[i].rise(queue.event(rise_handler)); + // } + txByte0.rise(rise_handler); + txByte1.rise(rise_handler); + txByte2.rise(rise_handler); + txByte3.rise(rise_handler); + txByte4.rise(rise_handler); + txByte5.rise(rise_handler); + txByte6.rise(rise_handler); + txByte7.rise(rise_handler); + + uint8_t seq = 0; // Set initial transmit sequence to 0 printf("\r\nreset-tx "); // Start radio transmitter after POR or reset - Radio::Init(&rev); + loRaRadio.Init(&rev); //Set radio properties for transmitter - Radio::Standby(); - Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1); - Radio::SetChannel(CF_HZ); + loRaRadio.Standby(); + loRaRadio.LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1); + loRaRadio.SetChannel(CF_HZ); // Set transmitter output power - Radio::set_tx_dbm(TX_DBM); + loRaRadio.set_tx_dbm(TX_DBM); // Setup transmit packet payload -> preambleLen, fixLen, crcOn, invIQ - Radio::LoRaPacketConfig(8, false, true, false); + loRaRadio.LoRaPacketConfig(8, false, true, false); printf("\n"); printf("%02d \r\n\n", seq); - for (;;) { - Radio::radio.tx_buf[0] = seq; // set payload + for (;;) {} + + // loRaRadio.radio.tx_buf[0] = seq; // set payload + // txDone = false; + // loRaRadio.Send(10, 0, 0, 0); // begin transmission of payload + + // while (!txDone) { + // loRaRadio.service(); + // } + + // // Transmit payload every 500mS + + // wait(0.5); // throttle sending rate + // seq++; // change payload (increment sequence number) + // printf("%02d \r\n\n", seq); // Print sequence number + + //} +} + +void transmit( uint8_t byte) +{ + //volatile bool tx_Done; + loRaRadio.radio.tx_buf[0] = byte; // set payload txDone = false; - Radio::Send(10, 0, 0, 0); // begin transmission of payload + loRaRadio.Send(1, 0, 0, 0); // begin transmission of payload while (!txDone) { - Radio::service(); + loRaRadio.service(); } - - // Transmit payload every 500mS - - wait(0.5); // throttle sending rate - seq++; // change payload (increment sequence number) - printf("%02d \r\n\n", seq); // Print sequence number - - } + printf("transmission complete\n\r"); }
diff -r b277f5a65c1c -r cfd70a2fb81f mbed_app.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_app.json Sun May 09 20:03:44 2021 +0000 @@ -0,0 +1,10 @@ +{ +"config": { + "thread_stack_size": { + "value": 2048 + }, + "main_stack_size": { + "value": 2048 + } + } +} \ No newline at end of file