CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Master/slave spi communication
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 15, 2010 11:43 pm     Reply with quote

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

View user's profile Send private message

Spi & RFM12BP
PostPosted: Fri Jun 18, 2010 12:45 am     Reply with quote

RF module : RFM12BP
manufacturer : Hoperf

Data sheet:
http://www.hoperf.com/upfile/RFM12BP.PDF

Thanks PCM programmer
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 18, 2010 3:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jun 19, 2010 1:11 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jun 19, 2010 2:05 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 21, 2010 7:26 am     Reply with quote

avami wrote:
Thanks for your useful explanations again Smile

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

View user's profile Send private message

PostPosted: Fri Jun 25, 2010 1:26 am     Reply with quote

Thanks
I try that.
avami



Joined: 10 Jun 2010
Posts: 11
Location: Mashhad

View user's profile Send private message

PostPosted: Tue Jun 29, 2010 7:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jun 29, 2010 1:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 03, 2010 6:39 am     Reply with quote

I mean PIC's internal registers
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group