Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main4-2.cpp
00001 00002 //送信用プログラム 00003 00004 #include "mbed.h" 00005 #include "nRF24L01P.h" 00006 RawSerial pc(PA_2, PA_3,115200); 00007 AnalogIn mic_in(A0); 00008 AnalogOut sp_out(A2); 00009 Ticker interrput; 00010 #define TRANSFER_SIZE 16 00011 int out_flg = 1; 00012 int snd_flg = 0; 00013 uint16_t txData[TRANSFER_SIZE*2]; 00014 int txDataIdx = 0; 00015 int rxDataCnt = 0; 00016 00017 nRF24L01P my_nrf24l01p(D11, D12, D13, D10, D9,D8); // mosi, miso, sck, csn, ce, irq 00018 //nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq 00019 00020 00021 void timer(){ //タイマー割り込みによるMic in 16回ごとに送信 00022 uint16_t ain; 00023 if(1 /*out_flg*/){ 00024 ain= mic_in.read_u16(); 00025 txData[txDataIdx] = ain; 00026 txDataIdx++; 00027 if (txDataIdx == TRANSFER_SIZE) {//最初の16回 00028 snd_flg = 1; 00029 } else if (txDataIdx >= TRANSFER_SIZE*2){//後の16回 00030 txDataIdx=0; 00031 snd_flg = 2; 00032 } 00033 // pc.printf("in %d\r\n",ain); 00034 // sp_out.write_u16(ain); 00035 //out_flg = 0; 00036 } 00037 } 00038 00039 int main() { 00040 // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's 00041 // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019) 00042 // only handles 4 byte transfers in the ATMega code. 00043 int i=0; 00044 wait_ms(100); 00045 00046 00047 my_nrf24l01p.powerUp(); 00048 my_nrf24l01p.setRfFrequency(NRF24L01P_MIN_RF_FREQUENCY);//2400-2525 00049 my_nrf24l01p.setRfOutputPower(NRF24L01P_TX_PWR_MINUS_12_DB);//mAX 0 -6 -12 -18 00050 my_nrf24l01p.setAirDataRate(NRF24L01P_DATARATE_1_MBPS);//250k,1000,2000K 00051 // Display the (default) setup of the nRF24L01+ chip 00052 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); 00053 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); 00054 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); 00055 pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); 00056 pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); 00057 00058 pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE ); 00059 my_nrf24l01p.setTransferSize( TRANSFER_SIZE * sizeof( uint16_t ));//mAX 4 00060 00061 my_nrf24l01p.setReceiveMode(); 00062 my_nrf24l01p.enable(); 00063 00064 wait_ms(10); 00065 interrput.attach_us(&timer, 100);//100 usec 10Khz 00066 00067 while (1) { 00068 i++; 00069 if (snd_flg==1) {//最初のバッファ 00070 snd_flg=0; 00071 my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char *)txData , TRANSFER_SIZE * sizeof(uint16_t) ); 00072 // pc.putc('1'); 00073 } 00074 else if (snd_flg==2) {//後半のバッファ 00075 snd_flg=0; 00076 my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char*)(txData+TRANSFER_SIZE) , TRANSFER_SIZE * sizeof(uint16_t) ); 00077 // pc.putc('2'); 00078 00079 } 00080 } //for while(1) 00081 }
Generated on Mon Aug 22 2022 22:57:21 by
1.7.2