ATMega1284P internal functions + digitalWrite

I am using an ATMega1284P on a custom Bobuino board, with a RF24L01 radio module.

The module uses SPI and i have chosen to connect the CSN chip select pin to bobuino pin 29, which connects to ATMega1284P port C pin 7.

This port is named "PCINT23/TOSC2_PC7" and it corresponds to 1284 pin 29.

I need to use this pin to control the ON/OFF slave select of the RF module, so i have declared:

pinMode(29,OUTPUT);

and use digitalWrite to set it HIGH or LOW. In the setup function of the Sketch i set pinMode and set it LOW so that it will be active.

My loop function is this:

void loop(void)
{
radioReceive();
radioSend();
delay(5000);
}

Where receive and send are functions for radio communication. My program loops once fine and then the chip select goes automatically to HIGH and turns off my module. I tried using digitalWrite to set the CS pin back to LOW and i see that in the beginning of the loop (second time and every time after the second) and after running each radio function the uC tries to set the pin back to HIGH and for a fraction of a second it goes HIGH and then it's set back to LOW because i give the digitalWrite LOW command.

I can't seem to understand if the CS pin is set to HIGH by default (if it happens in all sketches) or if it has something to do with the 1284P internal pin being used for some other internal function.

Are you using a pre written library for the n2401? Have you looked at how it
handles the CS pin?

oric_dan:
Are you using a pre written library for the n2401? Have you looked at how it
handles the CS pin?

I am using RF24Network. I'll have a look at it now. In any case, this library allows the user to choose CSN and CE pins.

edit: you were right, RF24Network is using the RF24 library which has built in code for the CE and CSN pins and uses pinmode and digitalwrite. I will have a look at it and post results! :smiley: