Usage of RF-24G module and Atmel AVR Mega8 SPI

I have seen a lot of talk about useage of the RF-24G and the AVR SPI interface. I am working on useing this with Lars Jonsson’s code. But I have not actualy seen a schematic so thought I would post what I think is correct and see if anyone see’s anything wrong with it.

Mega8-----------RF-24G

PB3 (MOSI)-----Data

PB4 (MISO)-----Data

PB5 (SCK)------CLK1

PD2 (INT0)-----DR1

PD4--------------CS

PD5--------------CE

No Connect-----DOUT2

No Connect-----CLK2

No Connect-----DR2

According to the Nordic PDF about SPI connecting the MOSI / MISO pins together to data is the right thing to do. I am not using the 10K resistors they recomend as this is the only SPI device in the system.

Not beeing a HW expert I included the the 10K resistors in my setup. I may be wrong but are they not needed also when the RF-24G is the only device? In the case where the RF-24G outputs on “data” the MOSI line would be fighting that signal if there is no resistor?

The other pin connections look ok. DR1 on INT0 is useful so you may decide later if you want to use an interrupt for when data is ready.

/Lars

I discovered a really good reason to include them. ISP. the SPI port is used by the ISP functionality. And if the resistors arn’t there you can’t program in circuit.

So I added them:

PB3 → 10K → Data

PB4 → 10K → Data

And now ISP is working as expected. And I appear to be getting data out the SPI port.

One additional note I ran into. On the Mega8 at least you have to set the !SS pin as an output or put an external pullup on it. If you don’t when you set the SPI master mode if !SS ever goes low the chip will drop out of master mode (a bus collision mechanisum). By setting it an output you avoid this problem.

Next phase is to build a stand alone board to act as my reciver (been working on the STK500 but only have one) and see if I am actualy sending data when I say to.

How do I go about debugging a link problem? I think my transmiter module is working though I can’t be sure.

But I never get DR1 set on my recivieng unit.

If anyone wants to take a look at my code you can find the project (WinAVR based) at:

www.oz.net/~davids/Mega8_SPI_Radio.zip

We have developped BASCOM Lib Function for AVR Full compatible with SMIRF2. We had some problems with SPI.

_rf_ddr_port Alias Ddrc
_rf_out_port Alias Portc
_rf_in_port Alias Pinc
_rf_data1 Alias 1                                         'I/O
_rf_clk1 Alias 3                                            'O
_rf_ce Alias 5                                              'O
_rf_cs Alias 6                                              'O
_rf_dr1 Alias 4                                             'O

Declare Function Rf_receive(rf As String ) As Byte   ' Receive bytes
Declare Function Rf_send(rf As String ) As Byte       'Tranmit bytes
Declare Function Rf_config(byval Rf_par As Byte) As Byte 'Config TRW24G

One problem could be the SPI speed. Looks like you have 2Mhz (maybe because of less than clear comments in my code). Remove the

SPSR |= (1<<SPI2X); 

line in trf24gInit() to get /4 i.e., 1Mhz (which is what I run).

/Lars

I have tried both with and without that line. Doesn’t seem to make any differance.