i2c fast mode (1MHz) and high speed mode (3.4MHz)

edmunds

Senior Member
Dear all,

Would the faster [h]i2c modes be available with picaxe with some number instead of constants i2cslow_x and i2cfast_x?


Thank you for your time,

Edmunds
 

Goeytex

Senior Member
Grab the PIC datasheet for the Picaxe that you are using then go to the "MSSP" section. The I2C speed is determined by BRG (Baud Rate Generator) setting in the SPPxADD Register. The BRG is basically a count down timer.

There is a chart that tells you what speeds are available and what register settings to use based upon the PIC clock speed.

You should be able to "pokeSFR" the value into the register to change the speed. Standard speeds are 100K and 400K for I2C. Trying to operate I2C at much higher speeds may yield poor results.

You can find the register address for the SPP1ADD register in the "Memory Organization" section of the Datasheet. Picaxe Help for POKESFR will describe the method for writing the specific register.

The PIC MSSP module is not capable of nor is it rated for HS I2C as that requires that the I2C Pins both source and sink current. PIC I2C MSSP peripheral pins use pull-up resistors and do not source current.

That being said, I have tweaked a PIC I2C clock up to about 700K with some success.
 
Last edited:

inglewoodpete

Senior Member
Grab the PIC datasheet for the Picaxe that you are using then go to the "MSSP" section. The I2C speed is determined by BRG (Baud Rate Generator) setting in the SPPxADD Register.
@Edmunds, After checking in the appropriate data sheet that the chip you are using is capable of i2c at the faster speed, try some simple experiments.

If you use the command "hi2cSetup i2cMaster, address, i2cFast_64, i2cByte" and then SetFreq the PICAXE to 32MHz, the i2c will run at 800kbits/sec. With the same i2cSetUp command at 16MHz, i2c will run at 1.6Mbits/sec. However, you will need to keep the bus length very short at those speeds - I presume you are already aware of this.
 
Last edited:

westaust55

Moderator
Yes higher i2c and Hserout comms speeds are certainly possible.

For my DCC Accessory decoder project with a 20X2 running at 64 MHz as the i2c slave and an 28X2 running at 80 MHz (20 MHz resonator) as the i2c Master, for example purposes here are the relevant lines of code based on the tables and formula in the PIC datasheet:

Code:
SYMBOL i2cFAST_72 = 17  ; 22 ; 17 equates to ~1 MHz i2c clock speed / 22 for ~800 kHz
SYMBOL i2cFAST_80 = 19  ; 24 ; 19 equates to ~1 MHz i2c clock speed / 24 for ~800 kHz
	Hi2cSETUP i2CMASTER, %10100000, i2cFAST_80, i2cBYTE	; Set up i2c comms for reading data from PICAXE #1

Note the HSERSETUP is used to send via HSEROUT data to the front right and Right Scenic modules to control lights and features.
SYMBOL b76800_72 =233
SYMBOL b76800_80 = 265 ; 260 - 273 range worked
SYMBOL  b1200_80 = 16666
SYMBOL   b600_80 = 33332

;	HSERSETUP b600_80, %00010010 ; 600 baud with 80 MHz clock, inverted TXD/Serial Output
During testing I was using Hserout to send data to a PC at 76800 baud rate for display of data for checking purposes.


In line with IWP's comments regards bus length, my i2c bus was only of the order of 30 mm max length with the 20X2 and 28X2 virtually end to end with pins 10/11 close to pins 14/15
 

Goeytex

Senior Member
If this is just Picaxe to Picaxe Comms then I would probably use HSPI instead of I2C if the necessary added pins are available. The signal integrity will be better and it can run much faster.

IN either case the speed bottleneck will be the command latency and not the I2C or HSPI Clock speed. In other words on a Picaxe, I2C at 2MHz will not transfer 20 bytes of data two times faster than I2C at 1MHz. It will likely only be about 10% faster. ( Assuming it will work at all at 2MHz.)

HSPI should work nicely at 8 MHz.
 
Last edited:

edmunds

Senior Member
Thanks, guys, very quick and thorough, as usual :).

I was thinking about it to save some microseconds with FRAM access. Will consult the PIC data sheet.

Edmunds
 
Top