Friday, April 13, 2007

Simple AVR wireless communication using Cypress Wireless USB modules

A simple way of adding wireless communication to your electronics projects is by using wireless USB modules by Cypress. These 2.4 GHz tranceiver (both TX&RX on each module) modules have very low power consumption, over 50m range (over 200m with non-PCB antenna) and cost $10 in quantities of 1 (one). Cypress also offer samples of all their wireless products so you can test them out before you buy. I will show how to interface the CYWM6934 and CYWM6935 modules (they are pin compatible and interchangeable, just different range) (it should work with the CYWM6935PAEC aswell since it's just a CYWM6935 with a power amplifier) with a Atmel AVR mega8 microcontroller.
The modules consists of a wireless transceiver (CYWUSB6934 or CYWUSB6935), a PCB antenna, some passive components, a crystal and a pin header for connecting to the module. Communication between the transceiver and the AVR is done via SPI, which the AVR has hardware support for. The only components needed besides the AVR and the module is +5V and +3.3V power supplies. I used L7805CV for +5V and LM317T for +3.3V (better to use a dedicated 3.3V regulator, but couldn't find one on short notice).
To have something fun to send over the wireless link I connected a Dallas DS1820 temperature sensor (also available as samples) to the transmitting side (any DS18X20 sensor works, DS1820, DS18S20 and DS18B20). To read the temperature sensor I used a collection of code from Martin Thomas. I also used some USART code from Jaakko Ala-Paavola. The following photo shows the first test setup with two CYWM6934 connected to one AVR mega8 each.


After initial testing I moved the module with the temperature sensor to a separate board for range testing. Pinouts for the modules can be found in their datasheets and pin connections to the AVR can be found in the source code (wireless_tx.c and wireless_rx.c).
My code for interacting with the wireless module is available on Google code:
http://code.google.com/p/cywusb

Have fun!

26 comments:

chandan2002x said...

????????????????Where is the code and the schematics????

Google fail or uuuuuu?? or me???

Unknown said...

It's there, just a few clicks away :)
At the Google code page click "Source", then "Subversion repository" and finally "trunk/". This will take you to:
http://cywusb.googlecode.com/svn/trunk/
where the source code is available for download.
Regarding schematics, I´ve got nothing more than what's described in my original post:
"Pinouts for the modules can be found in their datasheets and pin connections to the AVR can be found in the source code (wireless_tx.c and wireless_rx.c)."
Let me know how it works out!

Anonymous said...

I have translated your code for PIC18f4620
but reciver does not seam to work.any comment please?

Unknown said...

I've never worked with PIC so I'm not sure I can help you debug that.. Is everything else working? If you can make debug printouts (via serial-port to a computer) to check that you can read and write registers on both the receiver and transmitter that can help alot. The best would be to have both ends hooked up to serial terminals to be able to watch debug output in realtime on booth ends.. I can throw an eye at the code if you want but I've never looked at PIC-code before :)

Unknown said...

Hello, excellent work done...

We are working wireless tilt based accelerometer mouse but we found that as per your code why does receiver receives data twice...? when we are sending it only once..?

one more question -what maximum speed you have tried bcoz there is 50hs delay in program...?

i found that receiver skips some bytes(in very huge data)..?

We are using 3.4 v & 3.15 v as two supply for receiver & transmitter respectively..?

Thanks for wonderful work...

hope your comments will improve our knowledge as we are trying something timing critical..?

Unknown said...

one more question why in cywm_readreg you gave spi_write function twice..? for same data is it really necessary..?

Unknown said...

Hello Mahavir,
Thanks for the appreciation! I'll start by answering the only one of your questions I have a good answer to :/
Cywm_readreg calls spi_write the second time to shift the requested data from the slave to the master, i.e. to generate the spi clock. The data shifted from the master to the slave during the second write is simply discarded by the slave. Perhaps one should create a new function called spi_read that only writes a 0 byte or whatever.
As to your other questions, I can't remember ever getting the data twice. I did however experience some quite frequent data loss, i.e. some random bytes getting lost. I have not tried to solve this problem so I don't know why it happens.
I have not performed any speed tests so I have no idea what the maximum speed is but I suppose it ought to be close to the 62.5 kbits/sec mentioned in the datasheet.
The power supplies you use are within the limitations so they should be fine.
Sorry for not being able to give better answers, just let me know if you need any more help or something.

Anonymous said...

ok. fine i got thr wireless communication its working fine.

but , i found that transmitter voltage boosts upto 3.6v or even more...with dedicated tc1262 3.3 regulator...

i am using same regulator for other cct so that cct might get damaged as its maximuum i/p voltage is 3.3v

did you find something like that?

Unknown said...

I'm not quite sure what you are asking for but I have never used a tc1262 regulator. It sounds wrong for a 3.3V regulator to go above 3.6V though.

Unknown said...

Hello !!! I am using PIC16F877A for controlling a robot so i need to interface CYWUSB6935 with it. Can anyone help me in this matter or kindly tell me the alternative? I m controlling a DC motor 2 STEPPER motors with the same controller on receiving side. Another PIC16F877A is used on transmitting side i have to get serial data from PC and send it through CYWUSB6935 to my ROBOT. Kindly help me in this matter

Unknown said...

Shakeeb said

Unknown said...

I m shakeeb

Anonymous said...

Hey, Lars

We finally came up with wireless accelerometer based mouse...

We got good range of around 10 meters with CYWM 6935 module

its on
http://coepetc.blogspot.com

Thanks to your work...

Regards
mahavir

Unknown said...

Mahavir, great to hear that you got it too work! I looked at the movie on your project page and it looks very nice, good work! Thanks for referencing me and I'm glad I could help :)

Anonymous said...

Hi,
I would like to know how the AVR is programmed. What firmware needs to be donwloaded to
1)Atmel chip having connection to the Dallas temperature sensor
2)The Atmel chip with connection to the receiver module.

Unknown said...

Hi, the source is available here: http://cywusb.googlecode.com/svn/trunk/
The makefile generates two hex-files, wireless_rx is for the receiver and wireless_tx is for the transmitter (that transmits the temperature from the dallas sensor).

Anonymous said...

Hey Lars

I found reason for power supply bugs as we were interfacing 5v to 3.3v module..We should have placed resistor divider at MOSI pin to match with voltage requirements of module...convert 5v to 3.3 v..

Quite a big problem...

I found it at in schematics

Spectrum Analyzer

Regards

Mahavir

Unknown said...

Interesting, what problems where you experiencing due to the high (5V instead of 3.3V) voltage? I assumed that the 3.3V cypress chip was TTL-compatible..

Anonymous said...

When i started transmitting data my TC1262 regulator voltage was going above 3.6volts ...

I think that even might cause problems in reception of error free data...loss of few bytes which i got in long stream....

We should make changes in blog entry as its important point in interfacing CMOS & TTL

Regards
Mahavir

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Unknown said...

A fellow human, Bas, has found a problem with timing in the following code:

high(PORTD, CYWM_nPD);
high(PORTD, CYWM_nRESET);

CYWM_WriteReg( REG_CLOCK_MANUAL, 0x41 );

Bas writes:

"The clock register was changed right after resetting the system and this seems to be too soon.
After adding some delay after setting the pd and reset pins the problem was fixed.
In your code there was some usart printing, which I removed, which probably made the delay big enough."


Thanks alot Bas!

Unknown said...

hi...
we are having problem in interfacing CYRF6936 with ATmega32.While reading the data from MISO pin,we aren't getting any data.It always stays high. Can u plz help us with the assembly code.
thanks

Unknown said...

hi,You have a very good blog that the main thing a lot of interesting and useful!usb protection , thanks

Unknown said...

Lars and mahavir thanks 4 ur conversation,it is indeed helpful 4 newcomers. Keep up d work

Dorothymcollier said...

Great post...thanks for sharing an informarive content. This is helpfull. Happ to be your new follower.
Wireless communication modules