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

Math help, I2C 1MHz sspadd calc

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



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

Math help, I2C 1MHz sspadd calc
PostPosted: Tue Nov 13, 2007 9:37 am     Reply with quote

I am trying to verify that the compiler is working right.
I am trying to get a 1MHz I2C setup. I'm using
Code:
#use I2C(MASTER,SDA=FRAM_SDA,SCL=FRAM_SCL,FORCE_HW,FAST,RESTART_WDT)

The list file shows
Code:
.................... #use I2C(MASTER,SDA=FRAM_SDA,SCL=FRAM_SCL,FORCE_HW,FAST,RESTART_WDT)
56E4:  BSF    F94.3
56E6:  BSF    F94.4
56E8:  MOVLW  18
56EA:  MOVWF  FC8

Code:
#use I2C(MASTER,SDA=FRAM_SDA,SCL=FRAM_SCL,FORCE_HW,FAST=1000000,RESTART_WDT)

The list file shows
Code:
.................... #use I2C(MASTER,SDA=FRAM_SDA,SCL=FRAM_SCL,FORCE_HW,FAST=1000000,RESTART_WDT)
56E0:  MOVLW  90
56E2:  MOVWF  FAB
56E4:  BSF    F94.3
56E6:  BSF    F94.4
56E8:  MOVLW  09
56EA:  MOVWF  FC8

The lower 7 bits SSPADD @ 0xFC8 controls the speed. for fast it is set to 18, for fast=1000000 it is set to 9
Is this calculated correctly?
I use a
#use delay(clock=40000000)
#fuses h4,wdt16384,noprotect,nolvp,put
10MHz clock and h4 pll.


Last edited by treitmey on Wed Nov 14, 2007 4:55 pm; edited 3 times in total
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Nov 13, 2007 9:45 am     Reply with quote

Code:

TABLE 17-3: I2C™ CLOCK RATE W/BRG
Fosc     FCY      FCY*2      BRGValue   FSCL
                                     (2 Rollovers of BRG)
40 MHz 10 MHz 20 MHz 18h 400 kHz(1)
40 MHz 10 MHz 20 MHz 1Fh 312.5 kHz
40 MHz 10 MHz 20 MHz 63h 100 kHz
16 MHz 4 MHz 8 MHz 09h 400 kHz(1)
16 MHz 4 MHz 8 MHz 0Ch 308 kHz
16 MHz 4 MHz 8 MHz 27h 100 kHz
4 MHz 1 MHz 2 MHz 02h 333 kHz(1)
4 MHz 1 MHz 2 MHz 09h 100 kHz
4 MHz 1 MHz 2 MHz 00h 1 MHz(1)
Ttelmah
Guest







PostPosted: Tue Nov 13, 2007 9:58 am     Reply with quote

Two things. Remember the values are hex. The division is by val+1.
So for 400K, is is dividing the clock by twenty five (0x18+1). The clock is selected as master clock/4. So:
40000000/(4*25) = 400000

Spot on.
For the 100K version, it divides by ten. So:

40000000/(4*10) = 1000000

Again spot on.

The compiler is doing it right.

Best Wishes
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Nov 13, 2007 10:07 am     Reply with quote

Cool
Thanks a bunch.
((Ttelmah:100k should read 1M in your post))


Belt and suspenders theory.
I'll also write a tight loop and check with scope.
With scope I get 1uS for half(5v part) cycle of the SCL pin.
I guess thats correct. But not sure. I expected 1us for a FULL cycle.
Ttelmah
Guest







PostPosted: Tue Nov 13, 2007 4:00 pm     Reply with quote

Er. I don't have '100K'in my post anywhere. The value I have, is 1000000, which is 1M, and is correct.
I'm easily capable of missing a zero, but I haven't...

Best Wishes
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Nov 14, 2007 4:44 pm     Reply with quote

no worries..
Quote:
Posted: Tue Nov 13, 2007 9:58 am


Quote:
Spot on.
For the 100K version, it divides by ten. So:

40000000/(4*10) = 1000000

Thank you for your help.
Very Happy
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