I have problem making bidirectional link, and now after a week of trials I do not have any more ideas what is wrong…
Idea is to make a program ( on cc2510dk-mini) that reads pushed buttons on one board and send it to the other (button is read once when it is pressed).
I wrote that, and it works like a charm.
#include <ioCC2510.h>
#include <ioCC2510_bitdef.h>
unsigned int i,j,s_1,s_2;
char status=0;
int S1(void){
if(P1_2 == 0){
for(i=0;i<2000;i++);
if(P1_2 == 0){
return 1;
}
else
return 0;
}
else
return 0;
}
int S2(void){
if(P1_3 == 0){
for(i=0;i<20000;i++);
if(P1_3 == 0){
return 1;
}
else
return 0;
}
else
return 0;
}
int main(void)
{
P1DIR =0x03;
P1_0 = 0;
P1_1 = 0;
// Set the system clock source to HS XOSC and max CPU speed,
// ref. [clk]=>[clk_xosc.c]
SLEEP &= ~SLEEP_OSC_PD;
while( !(SLEEP & SLEEP_XOSC_S) );
CLKCON = (CLKCON & ~(CLKCON_CLKSPD | CLKCON_OSC)) | CLKSPD_DIV_1;
while (CLKCON & CLKCON_OSC);
SLEEP |= SLEEP_OSC_PD;
// IOCFG2, IOCFG1, IOCFG0 --- Radio Test Signal Configuration--- default
SYNC1 = 0xD3;
SYNC0 = 0x91;
PKTLEN = 0x01; //1 Bajt info, +2 Bajta CRC
PKTCTRL1 = 0x00; // PQT=000 -sync word is always accepted
// APPEND_STATUS = NE! ; ADR_CHK = 00 (NE)
PKTCTRL0 = 0x04; //WHITE_DATA= 0; PKT_FORMAT[1:0] = 00 (normal mode) ; CC2400_EN = 0 (NE) ; CRC_EN = 1 (DA) ; LENGTH_CONFIG[1:0] = 00 Fixed packet length mode. Length configured in PKTLEN register
ADDR = 0x00;
CHANNR = 0x00;
FSCTRL1 = 0x0A; // Izlazna frekvencija
FSCTRL0 = 0x00;
FREQ2 = 0x5D; // Frequency control word, high byte.
FREQ1 = 0x93; // Frequency control word, middle byte.
FREQ0 = 0xB1; // Frequency control word, low byte.
MDMCFG4 = 0x86; // Modem configuration.
MDMCFG3 = 0x83; // Modem configuration.
MDMCFG2 = 0x13; // Modem configuration. Better Sensitivity ; GFSK ; MANCHESTER_EN = (NE) ; 30/32 sync word bits detected
MDMCFG1 = 0x22; // Modem configuration. FEC_EN=0; minimum number of preamble bytes = 4
MDMCFG0 = 0xF8; // Modem configuration.
DEVIATN = 0x44;
MCSM2 = 0x07; //default
MCSM1 = 0x30; //CCA_MODE[1:0]=11 If RSSI below threshold unless currently receiving a packet
// RXOFF_MODE[1:0]= Normal , TX isto
MCSM0 = 0x14; // FS_AUTOCAL[1:0] = 01 When going from IDLE to RX or TX (or FSTXON)
FOCCFG = 0x16; // Frequency Offset Compensation Configuration.
BSCFG = 0x6C; // Bit synchronization Configuration.
AGCCTRL2 = 0x03; // AGC control.
AGCCTRL1 = 0x40; // AGC control.
AGCCTRL0 = 0x91; // AGC control.
FREND1 = 0x56; // Front end RX configuration.
FREND0 = 0x10; // Front end RX configuration.
FSCAL3 = 0xA9; // Frequency synthesizer calibration.
FSCAL2 = 0x0A; // Frequency synthesizer calibration.
FSCAL1 = 0x00; // Frequency synthesizer calibration.
FSCAL0 = 0x11; // Frequency synthesizer calibration.
TEST2 = 0x88; // Various test settings.
TEST1 = 0x31; // Various test settings.
TEST0 = 0x09; // Various test settings.
PA_TABLE0 = 0x7E; // PA output power setting.
while (1){
s_1 = S1();
s_2 = S2();
while( ( s_1 == S1() ) && ( s_2 == S2() ) );
if(s_1){
/* Put radio in TX. */
RFST = RFST_STX;
/* Wait for radio to enter TX. */
while ((MARCSTATE & MARCSTATE_MARC_STATE) != MARC_STATE_TX);
P1 ^= 0x01 ;
RFD = P1;
}
if(s_2){
/* Put radio in TX. */
RFST = RFST_STX;
/* Wait for radio to enter TX. */
while ((MARCSTATE & MARCSTATE_MARC_STATE) != MARC_STATE_TX);
P1 ^= 0x02 ;
RFD = P1;
}
while ((RFIF & RFIF_IRQ_TXUNF) == RFIF_IRQ_TXUNF){
P1_0 = ~P1_0;
P1_1 = ~P1_1;
for(i=0;i<10000;i++);
}
}
return 0;
}
but when I add a acknowledge of the sent package everything stops working.
When I look in RF-Studio, the first code is ok. It sends package only when button is pressed.
But when I add in the end of while(1) :
RFTXRXIF = 0;
RFST = RFST_SRX;
i=0;
while(!RFTXRXIF && i<60000){
i++;
}
if(RFTXRXIF){
P1 = RFD;
}
else P1 = 0x00;
if((RFIF & RFIF_IRQ_RXOVF) == RFIF_IRQ_RXOVF){
while (1){
P1_1 = ~P1_1;
for(i=0;i<60000;i++);
}
}
then the first package is sent correctly, but on the next pressing of a button it just sends preamble… also the light on the board that sends package works like everything is ok. So I guess something goes wrong when exiting RX, but I do not know what. Any help?
P.S. I also tried sending with interrupt function, but nothing works… on the second pressing of the button it sends only preamble (forever).