View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 15, 2010 11:43 pm |
|
|
Post the manufacturer and part number of your RF modules. Post a link
to the webpage for the modules, that has the data sheet. |
|
|
avami
Joined: 10 Jun 2010 Posts: 11 Location: Mashhad
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 18, 2010 3:50 pm |
|
|
I looked at the data sheets and appnotes. The RF12B chip is an SPI
slave device. That means the PIC is the SPI master. The RF12B will
give an interrupt to the PIC when any of several different conditions
occur. One of these conditions is when the receive fifo in the RF12B has
bits available to be read by the PIC.
To use all the features in the RF12B, a driver would have to be written.
They have sample code for the HiTech PIC C compiler, starting on
page 22:
http://www.hoperf.com/upfile/RF12B_code.pdf
They have code for the transmitter and the receiver. They don't use
an interrupt routine. They poll the nIRQ pin in a while() statement.
I think it's easier to start by doing it that way.
Basically, you need to translate those sample programs to CCS.
I don't have time to do it for you. You should do it. |
|
|
avami
Joined: 10 Jun 2010 Posts: 11 Location: Mashhad
|
|
Posted: Sat Jun 19, 2010 1:11 am |
|
|
Thanks for your consideration
I had studied the example program before but I think the example program is not optimal
because they use SPI in manual method and they did not use standard codes. The sample code is with HiTech PIC C compiler and It's for RFM12B, Not RFM12BP
So I decided to write all program.
I think It's better to use external interrupt to read data from SPI port when the data is available, But I don't know how I use the external interrupt to read data from SPI, If you know please help me.
It will be useful in the other projects.
Thanks again |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 19, 2010 2:05 pm |
|
|
Some things I see wrong with your PIC receiver code are:
1. You have the SPI configured as a Slave in the setup_spi() statement.
But that won't work, because the RF12BP is an SPI Slave device. The PIC
must be the master.
2. In your #int_ext routine, you don't have a 0 parameter in the
spi_read() statement. Since the PIC must be a master, it must also
generate the SCLK. To do that, the spi_read() statement must have
a parameter added (usually this is 0x00).
3. The nIRQ interrupt from the RF12BP can have several causes.
I think you need to read the status register from the RF12BP to see
which event caused it to generate the interrupt. It might be possible
to mask off some of these events. I didn't read the RF12B chip's data
sheet closely enough to see if this is possible. Study the sample code
in the HopeRF appnotes to find more information.
I don't really want to write the driver. You need to do this. |
|
|
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Mon Jun 21, 2010 7:26 am |
|
|
avami wrote: | Thanks for your useful explanations again
Quote: |
Does the RF module have a Chip Select pin on it ?
|
Yes it has but I connected it to GND for ever, because I use just one device.
|
Really? That's a bad move. Most devices won't accept the command if you don't raise the CS line after you are done sending the command. Just look at the timing diagram on page 1 of the datasheet. All you are doing is reading in gibberish. |
|
|
avami
Joined: 10 Jun 2010 Posts: 11 Location: Mashhad
|
|
Posted: Fri Jun 25, 2010 1:26 am |
|
|
Thanks
I try that. |
|
|
avami
Joined: 10 Jun 2010 Posts: 11 Location: Mashhad
|
|
Posted: Tue Jun 29, 2010 7:42 am |
|
|
Thanks "PCM programmer"
I have done that you suggested and my SPI worked with external interrupt very well.
Quote: |
You can't put any lines of code in-between the #int_ext and the start of
the interrupt routine.
|
How can I learn setting of registers? Could you please suggest me a good source?
Thanks again. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 29, 2010 1:30 pm |
|
|
What do you mean by "setting the registers" ? Do you mean the PIC's
internal registers ? Or do you mean the registers in the RF12BP ? |
|
|
avami
Joined: 10 Jun 2010 Posts: 11 Location: Mashhad
|
|
Posted: Sat Jul 03, 2010 6:39 am |
|
|
I mean PIC's internal registers |
|
|
|