Example code for RFM70 and ATmega88

In different groups I have seen messages from people trying to get RFM70 to work with the AVR. I've faced the similar problem, when I needed to connect RFM70 to the USART working in the SPI mode. The problem which disturbed operation of RFM70 was associated with incorrect SPI frames generated by ATmega88, when I set SS (CSN in RFM70) line high right after the RXC0 flag was set. To obtain the correct operation, I had to modify the standard SPI transfer routine in the following way:

static inline uint8_t SPI_Transfer(uint8_t c) { const uint8_t status_mask=((1

Reply to
wzab
Loading thread data ...

If the compiler will generate a listing in assembley language, I'd check the "status_mask" first thing.

Hul

wzab wrote:

formatting link

Reply to
dbr

formatting link

Thanks for the code, I'll take a look.

Can you tell me what the 'X' on the front of so many lines is for ??

Thanks

hamilton

Reply to
hamilton

s

This is a "shar" archive (according to the alt.sources convention). You can save the whole post (in an original form) and run "unshar" on it. Or you can remove all lines before the "#!/binsh" line, and run the remainder as the bash script. The above applies to Linux or other Un*x-like systems. I don't know how to unpack it in Windows (unless you make it Un*x like by installing cygwin

formatting link
)

-- Regards, Wojtek

Reply to
wzab

avr-gcc treats it just as it was a constant defined by #define. The generated code is quite efficient:

while ( (UCSR0A & status_mask) !=3D status_mask ); f6: 80 91 c0 00 lds r24, 0x00C0 fa: 80 7c andi r24, 0xC0 ; 192 fc: 80 3c cpi r24, 0xC0 ; 192 fe: d9 f7 brne .-10 ; 0xf6 /* Get and return received data from buffer */

-- Regards, Wojtek

Reply to
wzab

Ooops, it seems, that the TXC0 flag is not so easy to use. It is cleared only after interrupt or after writing "1" to it (in polling mode). So the above function must be slightly modified!

static inline uint8_t USART_SPI_Transfer(uint8_t c) { const uint8_t status_mask=3D((1

Reply to
wzab

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.