Thank you BobK for your reply.
I already know about I2C timing protocol, and I use it in many project already. I just need it to read an EEPROM faster than I2CREAD can do.
Thanks for your help but a 10ms pause will not give me speed...
Thank you BobK for your reply.
I already know about I2C timing protocol, and I use it in many project already. I just need it to read an EEPROM faster than I2CREAD can do.
Thanks for your help but a 10ms pause will not give me speed...
I don't know what PIC you are using, so I can't promise anything, but I've attached a file containing some portions of code I have used with the hardware I2C on a PIC 18F4620.
The file is a compilation of cut and past from a few include files, and has only been minimally "cleaned up" for public viewing. It has 4 sections:
1) Basic PIC and HSEROUT setup (mostly to reinforce what pic and how it's configured)
2) The meat of the I2C commands
3) Samples of Large Block Reading/Writing to an EEPROM
4) Samples of Reading/Writing to an RTC
Hopefully this will get you started.
Best of luck,
Steve B
Disclaimer: Looking a little closer I recall this being one of my first PBP-ASM items I tackled. It worked, and with other things pressing, I haven't gone back and cleaned things up, like unused variables (DelayCtr1 and DelayCtr2) and rements of HSEROUT commands used to debug.
Last edited by SteveB; - 20th January 2007 at 06:50. Reason: Added disclaime
Thank you SteveB, looks like what I need. I will take a closer look and adapt it to my needs. I'm using a PIC16F886, but I think all MSSP modules work the same way, and I only need to read from the EEPROM.
A couple of things right off the top of my head. The buffer size will need to be reduced for a 16F. Also, the way I allocated variables to "BANKA" or "BANKX" in the declaration statements will also need changing. If I get a chance later I'll try to give it a look-over for anything else. As I recall, I think I got the basics of the ASM routines from a Microchip document/source, and adapted them for the 18F. So that might also be an avenue to persue.
Steve B
Hi,
SteveB your routines are neat (at least than mine) and I learnt from it as well. Thanks to you and Toley for raising the topic.
Regards
Sougata
I made a quick run through the code (while my kids took a nap). Changed all the ASM to PBP. Also modified the buffer size, and some SFR lables to correspond the 16F. It compiles OK, but no 16F's to test it (nor anything to setup the circut without canibalizing something else). Keep in mind, on many of the 18Fs, you've got RAM to burn, so the buffers reflect that. On the 16Fs, you don't have that luxary.
Hopefully, if you are working it on your end, you can compare/use what I've done to move further down the road.
I did notice a number of areas where things could be improved or I would do thing differently. The error handling is especially weak. However, I never got any errors with the code and my setup, so never needed it to be very robust. So, I will put this on my *LONG* list of things to do when I get around to it.
SteveB
Last edited by SteveB; - 21st January 2007 at 05:58.
Thank you SteveB, with your help (and a lot of time) I finally make it work. I've changed some things in your Routines. First I changed the Labels for shorter names. I've also changed the lines refer to PIR1.3 for SSPSTAT.2 to indicate when a transmit is over. And I fixed a little error in your code RCEN is SSPCON2.3 instead of SSPCON2.4.
In Fact all that is need is to correctly set the MSSP module :
SSPSTAT.7 = 0 'High Speed Filter
SSPADD = $0C '400 kHz @ 20 MHz
SSPCON = %00101000 'I2C Master Mode Enable
And in your main program use the 6 next sub routines as needed :
;-----------------------------------------------------------
; Process Routines
;-----------------------------------------------------------
I2CSTART:
SSPCON2.0 = 1 ; SEN - Start Condition Enable Bit
WHILE SSPCON2.0 = 1 : WEND ; Wait for Start to complete
RETURN
;-----------------------------------------------------------
I2CRD:
SSPCON2.3 = 1 ; RCEN - Enable receive mode
WHILE SSPCON2.3 = 1 : WEND ; Wait for Read to complete
I2CDATA = SSPBUF
Return
;-----------------------------------------------------------
I2CWR:
SSPBUF = I2CDATA ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave 1=NotAck
RETURN ; Acknowledge recieved
Return
;-----------------------------------------------------------
I2CSTOP:
SSPCON2.2 = 1 ; PEN - send stop bit
While SSPCON2.2 = 1 : Wend ; Wait for SSP to complete
Return
;-----------------------------------------------------------
I2CNOACK:
SSPCON2.5 = 1 ; ACKDT - Set Ack bit to NotAck
SSPCON2.4 = 1 ; ACKEN - send ACKDT bit
While SSPCON2.4 = 1 : Wend ; Wait for SSP to complete
Return
;-----------------------------------------------------------
I2CACK:
SSPCON2.5 = 0 ; ACKDT - Set Ack bit to Ack
SSPCON2.4 = 1 ; ACKEN - send ACKDT bit
While SSPCON2.4 = 1 : Wend ; Wait for SSP to complete
Return
;-----------------------------------------------------------
Now By using thoses sub routines, I'm able to access an EEPROM fast enough to read a 8 sec. wav files at 8 kHz. Everything is written in PicBasic Pro (no assembly) and is at least 3 times faster than standard I2CREAD statement.
Ok I know it's not really "User friendly" but my programming skills are limited and it work fine for me like this. Maybe someone can write something easier to use, it could be very handy.
Bookmarks