Hallo,
ich möchte Daten von einem Attiny84A-PU zu einem Arduino Nano 33 IOT schicken und verwende dazu die Transceiver nRF24l01+. Auf der Arduino Seite funktioniert alles soweit aber am Attiny gibt es Probleme. Ich versuche im ersten Schritt radio.begin(), aber er geht nie aus der Loop heraus. Geprüft habe ich das durch ein LED, was nach dem Verlassen der Loop eigentlich ausgeschalten werden sollte. Ich verwende diese Schaltung:
- nRF24L01 VCC ---- VCC 1|o |14 GND --- nRF24L01 GND
-
PB0 2| |13 AREF -
PB1 3| |12 PA1 -
PB3 4| |11 PA2 --- nRF24L01 CE -
PB2 5| |10 PA3 --- nRF24L01 CSN -
PA7 6| |9 PA4 --- nRF24L01 SCK - nRF24L01 MOSI --- PA6 7| |8 PA5 --- nRF24L01 MISO
-
+----+
Bitte kann mir wer dabei helfen.
#include "SPI.h"
#include "RF24.h"
// CE and CSN are configurable, specified values for ATTiny85 as connected above
#define CE_PIN 2
#define CSN_PIN 3
//#define CSN_PIN 3 // uncomment for ATTiny85 3 pins solution
// instantiate an object for the nRF24L01 transceiver
RF24 radio(CE_PIN, CSN_PIN);
// Let these addresses be used for the pair
uint8_t address[][6] = { "1Node", "2Node" };
// It is very helpful to think of an address as a path instead of as
// an identifying device destination
// to use different addresses on a pair of radios, we need a variable to
// uniquely identify which address this radio will use to transmit
bool radioNumber = 0; // 0 uses address[0] to transmit, 1 uses address[1] to transmit
// Used to control whether this node is sending or receiving
bool role = true; // true = TX node, false = RX node
// For this example, we'll be using a payload containing
// a string & an integer number that will be incremented
// on every successful transmission.
// Make a data structure to store the entire payload of different datatypes
struct PayloadStruct {
char message[7]; // only using 6 characters for TX & RX payloads
uint8_t counter;
};
PayloadStruct payload;
void setup() {
// append a NULL terminating character for printing as a c-string
payload.message[6] = 0;
digitalWrite(PA7, HIGH);
// initialize the transceiver on the SPI bus
if (!radio.begin()) {
while (1) {} // hold in infinite loop
}
digitalWrite(PA7, LOW);
// Set the PA Level low to try preventing power supply related problems
// because these examples are likely run with nodes in close proximity to
// each other.
radio.setPALevel(RF24_PA_LOW); // RF24_PA_MAX is default.
// save on transmission time by setting the radio to only transmit the
// number of bytes we need to transmit a float
radio.setPayloadSize(sizeof(payload)); // char[7] & uint8_t datatypes occupy 8 bytes
// set the TX address of the RX node into the TX pipe
radio.openWritingPipe(address[radioNumber]); // always uses pipe 0
// set the RX address of the TX node into a RX pipe
radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1
if (role) {
// setup the TX node
memcpy(payload.message, "Hello ", 6); // set the outgoing message
radio.stopListening(); // put radio in TX mode
} else {
// setup the RX node
memcpy(payload.message, "World ", 6); // set the outgoing message
radio.startListening(); // put radio in RX mode
}
} // setup()
void loop() {
if (role) {
// This device is a TX node
bool report = radio.write(&payload, sizeof(payload)); // transmit & save the report
if (report) {
// transmission successful; wait for response and print results
radio.startListening(); // put in RX mode
unsigned long start_timeout = millis(); // timer to detect no response
while (!radio.available()) { // wait for response or timeout
if (millis() - start_timeout > 200) // only wait 200 ms
break;
}
radio.stopListening(); // put back in TX mode
// print summary of transactions
if (radio.available()) { // is there a payload received?
PayloadStruct received;
radio.read(&received, sizeof(received)); // get payload from RX FIFO
payload.counter = received.counter; // save incoming counter for next outgoing counter
}
} // report
// to make this example readable in the serial monitor
delay(1000); // slow transmissions down by 1 second
} else {
// This device is a RX node
if (radio.available()) { // is there a payload?
PayloadStruct received;
radio.read(&received, sizeof(received)); // get incoming payload
payload.counter = received.counter + 1; // increment incoming counter for next outgoing response
// transmit response & save result to `report`
radio.stopListening(); // put in TX mode
radio.writeFast(&payload, sizeof(payload)); // load response to TX FIFO
radio.txStandBy(150); // keep retrying for 150 ms
radio.startListening(); // put back in RX mode
}
} // role
} // loop