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 support@ccsinfo.com

18F252 with RFM42B - hardware SPI

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
madmax



Joined: 15 Nov 2011
Posts: 2

View user's profile Send private message

18F252 with RFM42B - hardware SPI
PostPosted: Tue Nov 15, 2011 8:50 am     Reply with quote

Hello.

Sorry for my bad English.

My problem:
I am trying to connect the CPU PIC18f252 with module RFM42B using hardware SPI. However, I have no response from the RF module.

1)
- I set the CPU clock 20MHz
- setup_spi (spi_master | spi_l_to_h | spi_clk_div_64)
- I set SDN at low level
- I set the SEL at low level
- spi_write (0x01)
- Result = spi_read ()
- I set a high-level SEL

I always get the result = 0

2)
- I set the CPU clock 20MHz
- setup_spi (spi_master | spi_h_tol | spi_clk_div_64)
- I set SDN at low level
- I set the SEL at low level
- Spi_write (0x01)
- Result = spi_read ()
- I set a high-level SEL

I always get the result = 0

When I set the level of SDN High - result = ff

Software SPI is working correctly - result always wynik = 06 is correct

Where I make mistake?

http://www.hoperf.com/upload/rf/RFM42B_43B.pdf
_________________
Piotr
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 15, 2011 1:14 pm     Reply with quote

Here is the data sheet:
http://www.hoperf.com/upload/rf/RFM42B_43B.pdf

Look on page 3. It shows the SPI timing. It shows that SCLK idles at
a low level and samples the data on the rising edge. This is SPI Mode 0.
You should add the following #define statements above main() and edit
the setup_spi() statement so it uses Mode 0. Example:
Code:

#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)

//========================
void main()
{
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_16);
.
.
.



Quote:

Result = spi_read ()

I always get the result = 0

This line will not produce the SPI clock, so it will not clock in the new data.
You need to add a 0x00 parameter to tell it to make the SCLK signal.
Example:
Code:

result = spi_read(0);
madmax



Joined: 15 Nov 2011
Posts: 2

View user's profile Send private message

PostPosted: Wed Nov 16, 2011 12:33 pm     Reply with quote

Thank you for help. Communication works. I did not know spi_read does not generate the clock signal Rolling Eyes.
_________________
Piotr
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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