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

SPI speed question

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



Joined: 03 May 2004
Posts: 48
Location: Sg

View user's profile Send private message

SPI speed question
PostPosted: Mon Sep 20, 2004 11:08 pm     Reply with quote

Hi, all,
I am new with SPI. I am now interfacing with a part with SPI interface.
According to the datasheet, its recommended speed is 115khz. How to set this speed using setup_spi()? Is it using spi_clk_div_16... these options? I did not see any clarification of the usage of these options on the PICC manual. Can anyone help?
Thanks.
Sigma
Sigma



Joined: 03 May 2004
Posts: 48
Location: Sg

View user's profile Send private message

PostPosted: Tue Sep 21, 2004 1:09 am     Reply with quote

By the way, my mcu freq. is 4Mhz. And also in the datasheet, it mentions something like 'The interval between the host lowering /SS and then generating the first SCK pulse should be a minimum of 3us.' How can this be achieved?
Sigma
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 21, 2004 3:00 am     Reply with quote

You didn't mention which processor you are using, but as most PICs are using the same hardware modules I will continue with the most common type.

The frequency generated for the SPI-bus is selected in the function setup_spi(). Possible options are: SPI_CLK_DIV_4, SPI_CLK_DIV_16,
SPI_CLK_DIV_64 and SPI_CLK_T2.
At a clock speed of 4MHz this will give you the following SPI-frequencies:
Code:
SPI_CLK_DIV_4:   1MHz
SPI_CLK_DIV_16:  250kHz
SPI_CLK_DIV_64:  62,5kHz
SPI_CLK_T2:      configurable 15Hz to 1MHz


Quote:
'The interval between the host lowering /SS and then generating the first SCK pulse should be a minimum of 3us.' How can this be achieved?

I guess /SS is the chip-select pin for your device? This is than connected to an I/O pin on the PIC, so you have total control over it. Just after lowering this output you will have to add a call to delay_us(3).
Sigma



Joined: 03 May 2004
Posts: 48
Location: Sg

View user's profile Send private message

PostPosted: Tue Sep 21, 2004 4:33 am     Reply with quote

Hi, ckielstra,
How to calculate SPI_CLK_T2 for 115khz using PIC16F76?
I saw some sample code as followed for 1khz.
What is the t2div?
Is it the '16' inside setup_timer_2(T2_DIV_BY_16,249,1)'s T2_DIV_BY_16?

Quote:

setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_T2);
// System 1ms tick.
// The cycle time will be (1/clock)*4*t2div*(period+1)
// In this program clock=16,000,000 and period=249
// (1/16000000)*4*16*250=1000 us or 1kHz)
setup_timer_2(T2_DIV_BY_16,249,1);

Thanks.
Sigma
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 21, 2004 5:39 am     Reply with quote

What kind of device are you using? I think it is very strange to be talking about a 'recommended' speed of 115kHz, most datasheets will specify a 'maximum' bus speed instead.

I would recommend to make life easier on yourself and forget about using timer2. Use the lower bus speed of 62kHz instead as this will make your application less time critical and you can use the timer2 for other functions in your program or turn it of to save power. Later when your application is working stable and you decide you need the extra performance you can always do the speed optimization.
Sigma



Joined: 03 May 2004
Posts: 48
Location: Sg

View user's profile Send private message

PostPosted: Tue Sep 21, 2004 7:11 pm     Reply with quote

It is some kind of RFID module. Actually i tried spi_clk_div_64, yet not working.
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