Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] The CC2500 is not responding

Status
Not open for further replies.

Pushpkant

Member level 1
Joined
May 17, 2014
Messages
39
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Location
India
Activity points
451
I have a cc2500 module MAR105p with SPI interface. When I connect this to ATmega8 MPU it is not responding.

The pin Connections are:

MAR105p -----> ATmega8
pin1 -----> 3.3V
pin2 -----> MOSI
pin3 -----> SCK
pin4 -----> MISO
pin5 -----> No connection
pin6 -----> GND
pin7 -----> PC1
pin8 -----> PC0
pin9 -----> No connection

The code for transmission is:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// This is First Test of Wireless tranciever module MAR105P
// The module contains CC2500 chip from TI
 
#define F_CPU 1000000UL
 
#include<avr/io.h>
#include<util/delay.h>
 
#include"CC_reg_values.h"
 
#define CSn     PC0
#define MOSI    PB3
#define SCLK    PB5
#define SS      PB2
 
void msdelay(unsigned int itime)
{
    unsigned int i,j;
 
    for(i=0; i<itime; i++)
    {
        for(j=0; j<100; j++)
        {
        }
    }
    return;
}
 
void SPI_init()     //initialize spi interface of atmega8
{
// Set MOSI, SCK as Output
    DDRB = (1<<5)|(1<<3);
 
    // Enable SPI, Set as Master
    //Prescaler: Fosc/16, Enable Interrupts
    SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
 
    PORTD = 0x02;
    msdelay(10);
    PORTD = 0x00;
}
 
 
unsigned char SPI_TX(unsigned char data)    // transmit and receive one byte from avr to CC
{
 // Load data into the buffer
    SPDR = data;
 
    //Wait until transmission complete
    while(!(SPSR & (1<<SPIF) ))
    {
        PORTD = 0x04;
        PORTD = 0x00;
    }
 
    // Return received data
    return(SPDR);
}
 
void command(unsigned char a)       // give commands to CC
{
    PORTC &= ~(1<<CSn);
 
    while(bit_is_set(PINB,PB4));
 
    SPI_TX(a);
    
    PORTC |= (1 << CSn);
}
 
// creating array for assigned register values
 
const unsigned char CC_rfSettings[0x2F]=
{
    CC_IOCFG2_value,
    CC_IOCFG1_value,
    CC_IOCFG0D_value,
    CC_FIFOTHR_value,
    CC_SYNC1_value,
    CC_SYNC0_value,
    CC_PKTLEN_value,
    CC_PKTCTRL1_value,
    CC_PKTCTRL0_value,
    CC_ADDR_value,
    CC_CHANNR_value,
    CC_FSCTRL1_value,
    CC_FSCTRL0_value,
    CC_FREQ2_value,
    CC_FREQ1_value,
    CC_FREQ0_value,
    CC_MDMCFG4_value,
    CC_MDMCFG3_value,
    CC_MDMCFG2_value,
    CC_MDMCFG1_value,
    CC_MDMCFG0_value,
    CC_DEVIATN_value,
    CC_MCSM2_value,
    CC_MCSM1_value,
    CC_MCSM0_value,
    CC_FOCCFG_value,
    CC_BSCFG_value,
    CC_AGCCTRL2_value,
    CC_AGCCTRL1_value,
    CC_AGCCTRL0_value,
    CC_WOREVT1_value,
    CC_WOREVT0_value,
    CC_WORCTRL_value,
    CC_FREND1_value,
    CC_FREND0_value,
    CC_FSCAL3_value,
    CC_FSCAL2_value,
    CC_FSCAL1_value,
    CC_FSCAL0_value,
    CC_RCCTRL1_value,
    CC_RCCTRL0_value,
    CC_FSTEST_value,
    CC_PTEST_value,
    CC_AGCTEST_value,
    CC_TEST2_value,
    CC_TEST1_value,
    CC_TEST0_value,
};
 
unsigned char p,q,r,t;
 
void send()     // send data in CC wirelessly
{
    command(SFTX);  //flush tx FIFO
    command(SIDLE); //turn CC2500 into idle mode
 
    command(SCAL);
    PORTC &= ~(1 << CSn);
 
    while(bit_is_set(PINB,PB4));
    SPI_TX(0x7F);       //tx FIFO address in brust mode
    SPI_TX(0x55);       // data byte 1
    SPI_TX(0xAA);       // data byte 2
    SPI_TX(PIND);       // data byte 3
 
    PORTC |= (1 << CSn);
 
    command(STX);        // command to send in tx fifo wirelessly
    _delay_us(10);
}
 
void receive()      // recieve data wirelessly in CC
{
    command(SRX);        //command to receive data wrelessly
    command(SRX);
 
    while(bit_is_clear(PINC,PC1));  //check GD0Pin of CC2500
    
    PORTC &= ~(1 << CSn);
 
    while(bit_is_set(PINB,PB4));
 
    SPI_TX(0xFF);       // rx FIFO address brust mode
    p= SPI_TX(0x00);    // data byte 1
    q= SPI_TX(0x00);    // data byte 2
    r= SPI_TX(0x00);    // data byte 3
 
    PORTC |= (1 << CSn);
 
    command(SFRX);      // flush receiver fifo
    command(SIDLE);     // turn CC in idele mode
    command(SCAL);
 
    PORTD = r;
}
 
void port_set()
{
    DDRC = 0xFD;
    DDRD = 0xFE;    // for transmitter
    return;
}
 
int main()
{
    //unsigned int j;
    unsigned char i;//,b;
 
    _delay_ms(5);
 
    port_set();
    
    SPI_init();
 
    PORTC |= (1 << CSn);
 
    for(i=0; i<0x2F; i++)   //configure register of CC2500
    {
        PORTC &= ~(1 << CSn);
        while(bit_is_set(PINB,PB4));
        
        SPI_TX(i);  // address byte
        SPI_TX(CC_rfSettings[i]);   // data byte
 
        PORTC |= (1 << CSn);
    }
 
    while(1)
    {
        // use send() in transmitter and receive() in receiver
    send();
    // receive();
    }
}



and receiver code is:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// This is First Test of Wireless tranciever module MAR105P
// The module contains CC2500 chip from TI
 
#define F_CPU 1000000UL
 
#include<avr/io.h>
#include<util/delay.h>
 
#include"CC_reg_values.h"
 
#define CSn     PC0
#define MOSI    PB3
#define SCLK    PB5
#define SS      PB2
 
void msdelay(unsigned int itime)
{
    unsigned int i,j;
 
    for(i=0; i<itime; i++)
    {
        for(j=0; j<100; j++)
        {
        }
    }
    return;
}
 
void SPI_init()     //initialize spi interface of atmega8
{
// Set MOSI, SCK as Output
    DDRB = (1<<5)|(1<<3);
 
    // Enable SPI, Set as Master
    //Prescaler: Fosc/16, Enable Interrupts
    SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
 
    PORTD = 0x02;
    msdelay(10);
    PORTD = 0x00;
}
 
 
unsigned char SPI_TX(unsigned char data)    // transmit and receive one byte from avr to CC
{
 // Load data into the buffer
    SPDR = data;
 
    //Wait until transmission complete
    while(!(SPSR & (1<<SPIF) ))
    {
        PORTD = 0x04;
        PORTD = 0x00;
    }
 
    // Return received data
    return(SPDR);
}
 
void command(unsigned char a)       // give commands to CC
{
    PORTC &= ~(1<<CSn);
 
    while(bit_is_set(PINB,PB4));
 
    SPI_TX(a);
    
    PORTC |= (1 << CSn);
}
 
// creating array for assigned register values
 
const unsigned char CC_rfSettings[0x2F]=
{
    CC_IOCFG2_value,
    CC_IOCFG1_value,
    CC_IOCFG0D_value,
    CC_FIFOTHR_value,
    CC_SYNC1_value,
    CC_SYNC0_value,
    CC_PKTLEN_value,
    CC_PKTCTRL1_value,
    CC_PKTCTRL0_value,
    CC_ADDR_value,
    CC_CHANNR_value,
    CC_FSCTRL1_value,
    CC_FSCTRL0_value,
    CC_FREQ2_value,
    CC_FREQ1_value,
    CC_FREQ0_value,
    CC_MDMCFG4_value,
    CC_MDMCFG3_value,
    CC_MDMCFG2_value,
    CC_MDMCFG1_value,
    CC_MDMCFG0_value,
    CC_DEVIATN_value,
    CC_MCSM2_value,
    CC_MCSM1_value,
    CC_MCSM0_value,
    CC_FOCCFG_value,
    CC_BSCFG_value,
    CC_AGCCTRL2_value,
    CC_AGCCTRL1_value,
    CC_AGCCTRL0_value,
    CC_WOREVT1_value,
    CC_WOREVT0_value,
    CC_WORCTRL_value,
    CC_FREND1_value,
    CC_FREND0_value,
    CC_FSCAL3_value,
    CC_FSCAL2_value,
    CC_FSCAL1_value,
    CC_FSCAL0_value,
    CC_RCCTRL1_value,
    CC_RCCTRL0_value,
    CC_FSTEST_value,
    CC_PTEST_value,
    CC_AGCTEST_value,
    CC_TEST2_value,
    CC_TEST1_value,
    CC_TEST0_value,
};
 
unsigned char p,q,r,t;
 
void send()     // send data in CC wirelessly
{
    command(SFTX);  //flush tx FIFO
    command(SIDLE); //turn CC2500 into idle mode
 
    command(SCAL);
    PORTC &= ~(1 << CSn);
 
    while(bit_is_set(PINB,PB4));
    SPI_TX(0x7F);       //tx FIFO address in brust mode
    SPI_TX(0x55);       // data byte 1
    SPI_TX(0xAA);       // data byte 2
    SPI_TX(PIND);       // data byte 3
 
    PORTC |= (1 << CSn);
 
    command(STX);        // command to send in tx fifo wirelessly
    _delay_us(10);
}
 
void receive()      // recieve data wirelessly in CC
{
    command(SRX);        //command to receive data wrelessly
    command(SRX);
 
    while(bit_is_clear(PINC,PC1));  //check GD0Pin of CC2500
    
    PORTC &= ~(1 << CSn);
 
    while(bit_is_set(PINB,PB4));
 
    SPI_TX(0xFF);       // rx FIFO address brust mode
    p= SPI_TX(0x00);    // data byte 1
    q= SPI_TX(0x00);    // data byte 2
    r= SPI_TX(0x00);    // data byte 3
 
    PORTC |= (1 << CSn);
 
    command(SFRX);      // flush receiver fifo
    command(SIDLE);     // turn CC in idele mode
    command(SCAL);
 
    PORTD = r;
}
 
void port_set()
{
    DDRC = 0xFD;
    DDRD = 0xFF;    // for receiver
    return;
}
 
int main()
{
    //unsigned int j;
    unsigned char i;//,b;
 
    _delay_ms(5);
 
    port_set();
    
    SPI_init();
 
    PORTC |= (1 << CSn);
 
    for(i=0; i<0x2F; i++)   //configure register of CC2500
    {
        PORTC &= ~(1 << CSn);
        while(bit_is_set(PINB,PB4));
        
        SPI_TX(i);  // address byte
        SPI_TX(CC_rfSettings[i]);   // data byte
 
        PORTC |= (1 << CSn);
    }
 
    while(1)
    {
        // use send() in transmitter and receive() in receiver
    //send();
    receive();
    }
}



The header file usded is:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Register values of CC2500
 
#ifndef _CC_REG_VALUES_H
#define _CC_REG_VALUES_H
 
// assign values to the registers
 
#define CC_IOCFG2_value     0x2F
#define CC_IOCFG1_value     0x2E
#define CC_IOCFG0D_value    0x06
#define CC_FIFOTHR_value    0x07
#define CC_SYNC1_value      0xD3
#define CC_SYNC0_value      0x91
#define CC_PKTLEN_value     0x03
/*
Indicate the packet length when fixed packet length is enabled.
If variable length packets are used, this value indicates the maximum lenght
packet allowed.
*/
 
#define CC_PKTCTRL1_value   0x04        //changed 0x80
#define CC_PKTCTRL0_value   0x04
#define CC_ADDR_value       0x00
/*
Addresses used for packet filteration optional broadcast addresses are 0x00 and 0xFF
*/
 
#define CC_CHANNR_value     0x00
/*
The 8 bit unsigned channel number which is multiplied by the channel spacing setting
and added to the base frequency.
*/
 
#define CC_FSCTRL1_value    0x09
/*
The desired IF frequency to employ in RX. Subtracted from FS base frequency in RX and
controls the digital complex mixer in the demodulator:
f_if = f_xosc / 2^10 * FREQ_IF
 
at 09 the frequency is 228515.625 Hz
at 15 the frequency is 380859.375 Hz
*/
 
#define CC_FSCTRL0_value    0x00
/*
Frequency offset added to the base frequency before being used by the FS
*/
 
#define CC_FREQ2_value      0x5D
#define CC_FREQ1_value      0xD8
#define CC_FREQ0_value      0x9D
 
/*
freq2 to freq0 are value of base frequency of frequency synthesiser
*/
 
#define CC_MDMCFG4_value    0x2D
#define CC_MDMCFG3_value    0x3B
#define CC_MDMCFG2_value    0x73
#define CC_MDMCFG1_value    0x23
#define CC_MDMCFG0_value    0x3B
 
#define CC_DEVIATN_value    0x01
 
#define CC_MCSM2_value      0x07
#define CC_MCSM1_value      0x30
#define CC_MCSM0_value      0x18
 
#define CC_FOCCFG_value     0x1D
#define CC_BSCFG_value      0x1C
 
#define CC_AGCCTRL2_value   0xC7
#define CC_AGCCTRL1_value   0x00
#define CC_AGCCTRL0_value   0xB2
 
#define CC_WOREVT1_value    0x87
#define CC_WOREVT0_value    0x6B
#define CC_WORCTRL_value    0xF8
 
#define CC_FREND1_value     0xB6
#define CC_FREND0_value     0x10
 
#define CC_FSCAL3_value     0xEA
#define CC_FSCAL2_value     0x0A
#define CC_FSCAL1_value     0x00
#define CC_FSCAL0_value     0x11
 
#define CC_RCCTRL1_value    0x41
#define CC_RCCTRL0_value    0x00
 
#define CC_FSTEST_value     0x59
#define CC_PTEST_value      0x7F
#define CC_AGCTEST_value    0x3F
#define CC_TEST2_value      0x88
#define CC_TEST1_value      0x31
#define CC_TEST0_value      0x0B
 
#define SRES                0x30
#define SFSTXON             0x31
#define SXOFF               0x32
#define SCAL                0x33
#define SRX                 0x34
#define STX                 0x35
#define SIDLE               0x36
#define SAFC                0x37
#define SWOR                0x38
#define SPWD                0x39
#define SFRX                0x3A
#define SFTX                0x3B
#define SWORRST             0x3C
#define SNOP                0x3D
 
#endif //_CC_REG_VALUES_H

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top