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.
Revision 1:dfc20a46ef43, committed 2021-01-15
- Comitter:
- rgoto
- Date:
- Fri Jan 15 06:26:55 2021 +0000
- Parent:
- 0:3b29eed48de4
- Commit message:
- finish
Changed in this revision
| main44-3.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main44-3.cpp Thu Dec 03 02:06:00 2020 +0000
+++ b/main44-3.cpp Fri Jan 15 06:26:55 2021 +0000
@@ -19,32 +19,17 @@
uint16_t rxData[TRANSFER_SIZE*2];
int rxDataIdx = 0;
int rxDataCnt = 0;
-static uint16_t end = 0;
+static uint16_t old = 0;
nRF24L01P my_nrf24l01p(D11, D12, D13, D10, D9,D8); // mosi, miso, sck, csn, ce, irq
//nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq
DigitalIn button(USER_BUTTON, PullUp); //送受信切り替え(押してる間だけ送信、離すと受信)
+
void timer(){ /*タイマー割り込みによるSPEAKER out*/
uint16_t ain;
if(button == 1){
- if(end == 0){ //static でendを定義することで一度だけバッファをリセットしたい
- for(txDataIdx=0; txDataIdx >= TRANSFER_SIZE; txDataIdx++){
- txData[txDataIdx] = 0;
-
- my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char *)txData , TRANSFER_SIZE * sizeof(uint16_t) );
-
- }
-
- for(txDataIdx=0; rxDataIdx >= TRANSFER_SIZE*2; rxDataIdx++){
- txData[txDataIdx] = 0;
-
- my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char *)txData , TRANSFER_SIZE * sizeof(uint16_t) );
- }
- end = 1;
-
- }
if(rcv_flg) {
out_flg=1;
@@ -58,7 +43,7 @@
//タイマー割り込みによるMic in 16回ごとに送信
if(button == 0){
- end = 0;
+ old = 0;
if(1 /*out_flg*/){
ain= mic_in.read_u16();//_u16という表現で16ビットとして受信するようにする
txData[txDataIdx] = ain;
@@ -75,7 +60,7 @@
}
}
}
-
+
int main() {
int bufferidx=0;
@@ -105,11 +90,20 @@
// my_nrf24l01p.flush_rx_fifo();
while(1){ //送受信をoenableで判断するため、それぞれのifを繰り返し見るためのwhile
if (button == 1) {
+ if(old == 0){ //このoldで、送信モードから受信に切り替わった時に一度だけリセットしたtxDataを送信する。これでもともとの受信側には変な音が残らない
+ memset(txData,0,sizeof(txData)/*何バイト書き込むか*/); //指定した場所のメモリをリセットする。
+ wait_ms(10);
+ my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char *)txData , TRANSFER_SIZE * sizeof(uint16_t) );
+ wait_ms(10);
+ my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char*)(txData+TRANSFER_SIZE) , TRANSFER_SIZE * sizeof(uint16_t) );
+ wait_ms(10);
+ old = 1;
+ }
// If we've received anything in the nRF24L01+...
if ( my_nrf24l01p.readable(NRF24L01P_PIPE_P0) ) { //受信?
// ...read the data into the receive buffer
- if (rxDataIdx < 16) bufferidx = TRANSFER_SIZE;
- else bufferidx = 0;
+ if (rxDataIdx < 16) bufferidx = TRANSFER_SIZE; //最初に後半の配列を読み込ませようとすることで、入力と出力がぶつからずに交互に行える!
+ else bufferidx = 0; //後半の空の配列を読み込んでる間、スピーカも空の前半配列を出力。スピーカが後半(読み込んだ空のやつ)を出力中に前半(ここからデータあり)を読み込み、スピーカが前半(データあり)を出力中に・・・
rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, (char*)(rxData+bufferidx),TRANSFER_SIZE * sizeof( uint16_t ) );
//myled1 = !myled1;
//if (rcv_flg==0)