Arduino uno can't sent data by nRF24L01

Sorry, I am trying to convert the SPWM signal into data and transmit the data with the nRF24L01 wireless transmission module, the following is my code
Is it because of the interruption of the program that my data cannot be transmitted normally?
if yes what should i do
thank you

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#include <avr/io.h>
#include <avr/interrupt.h>
#include <math.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define SinDivisions (20)
RF24 radio(7, 8); // CE, CSN

const byte address[][6] = {"Node1"};
const int potpin = A0;

static int microMHz = 16;
static int freq = 50;
static long int period;
static unsigned int lookUp[SinDivisions];
static char theTCCR1A = 0b10000010;
static int val;


void setup() {
  sbi(ADCSRA, ADPS2);
  cbi(ADCSRA, ADPS1);
  cbi(ADCSRA, ADPS0);

  Serial.begin(2000000);
  double temp;

  period = microMHz * 1e6 / freq / SinDivisions;

  for (int i = 0; i < SinDivisions / 2; i++) {
    temp = sin((i + 0.5) * 2 * M_PI / SinDivisions) * period * 0.9;
    lookUp[i] = (int)(temp + 0.5);
  }

  TCCR1A = theTCCR1A;

  TCCR1B = 0b00011001;

  TIMSK1 = 0b00000001;

  ICR1   = period;
  sei();             // Enable global interrupts.
  DDRB = 0b00000110; // Set PB1 and PB2 as outputs.

  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}
void loop() {
  static int val;
  val = analogRead(A0);
  val = map(val, 0, 1023, 0, 1023);

  Serial.println(val);
}

ISR(TIMER1_OVF_vect) {
  static int num;
  static int delay1;

  if (delay1 == 1) { /*delay by one period because the high time loaded into OCR1A:B values are buffered but can be disconnected immediately by TCCR1A. */
    theTCCR1A ^= 0b10100000;// Toggle connect and disconnect of compare output A and B.
    TCCR1A = theTCCR1A;
    delay1 = 0;             // Reset delay1
  } else if (num >= SinDivisions / 2) {
    num = 0;                // Reset num
    delay1++;
  }
  // change )duty-cycle every period.
  OCR1A = OCR1B = lookUp[num];
  num++;
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.