• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Oshonsoft Basic Low Level I2C

Status
Not open for further replies.

ericgibbs

Well-Known Member
Most Helpful Member
hi,
This modified example program is from the Oshonsoft manual, its uses the Basic low level I2C statements.
It will write the test data to the simulator EEPROM, but will not Read it back, it gets all FF's. I also get garbage in the real hardware.

If the 'Goto ep_read' is un remmed and the program re-run in the simulator it will read the test data OK.

If any Oshonsoft user has the time to check out this example and let me know what they find it would be appreciated.
I have sent a bug report to Vladimir.
Eric

Code:
'example 2:
'17Feb2015
'PIC 18F2550
'EEPROM 24C256

Define CLOCK_FREQUENCY = 20
AllDigital

Define I2CREAD_DELAYUS = 50
Define I2CCLOCK_STRETCH = 50

Dim addr As Word
Dim data(31) As Byte
Dim cnt1 as Byte

Symbol sda = PORTC.2
Symbol scl = PORTC.3

addr = 0

'goto ep_read
ep_write:
I2CPrepare sda, scl
I2CStart
I2CSend 0xa0
I2CSend addr.HB
I2CSend addr.LB
For cnt1 = 0 To 30 ' write 0 to 0xff to eeprom
I2CSend cnt1
Next cnt1
I2CStop

ep_read:
I2CStart
I2CSend 0xa1
For addr = 0 To 30
    I2CReceiveAck data(addr)
Next addr
I2CRecN data(31)
I2CStop
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Just simulated this on ISIS and it works fine..

Code:
'example 2:
'17Feb2015
'PIC 18F2550
'EEPROM 24C256

Define CLOCK_FREQUENCY = 20
AllDigital

Define I2CREAD_DELAYUS = 50
Define I2CCLOCK_STRETCH = 50

Dim addr As Word
Dim data(31) As Byte
Dim cnt1 As Byte

Symbol sda = PORTC.2
Symbol scl = PORTC.3

addr = 0

ep_write:
I2CPrepare sda, scl
I2CStart
I2CSend 0xa0
I2CSend addr.HB
I2CSend addr.LB
For cnt1 = 0 To 30  'write 0 to 0xff to eeprom
I2CSend cnt1
Next cnt1
I2CStop

WaitMs 20

ep_read:
I2CPrepare sda, scl
I2CStart
I2CSend 0xa0
I2CSend addr.HB
I2CSend addr.LB
I2CStop
I2CStart
I2CSend 0xa1
For addr = 0 To 30
I2CReceiveAck data(addr)
Next addr
I2CRecN data(31)
I2CStop
 

zas

New Member
Hello.
are the Port Pins for SDA and SCL correct. In the Datasheet it have to be PORTB.
I becom an error at the Line "I2CRecN data(31)". The Array have 31 Elements (0-30)
 

ericgibbs

Well-Known Member
Most Helpful Member
hi Ian,
Thanks for the feedback, if I hear from Vladimir I will post.
The Oshonsoft EEPROM sim tool works OK with the PORTB.0/1 , using the PIC's internal I2C module.
I have played with the delays without any success.
As I step thru the IDE, PICs buffer registers for the data(31) Array, during a Read operation, it loads a 0xFF into the buffer as it Reads the data.!

Eric
 

ericgibbs

Well-Known Member
Most Helpful Member
Hello.
are the Port Pins for SDA and SCL correct. In the Datasheet it have to be PORTB.
I becom an error at the Line "I2CRecN data(31)". The Array have 31 Elements (0-30)
Hi zas,
I am using the PORTB.0/1 for SPI [I2C pins] with a FAT32 SD card, that is why I want to use the low level I2C for a DS3231 RTC
The data(31) Array, is 32 Bytes long, that is data(0) thru data(31)

Eric
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
hi Ian,
Thanks for the feedback, if I hear from Vladimir I will post.
The Oshonsoft EEPROM sim tool works OK with the PORTB.0/1 , using the PIC's internal I2C module.
I have played with the delays without any success.
As I step thru the IDE, PICs buffer registers for the data(31) Array, during a Read operation, it loads a 0xFF into the buffer as it Reads the data.!

Eric
Have you tried the code I have written? Your "Read" routine was missing a few elements aswell...
 

ericgibbs

Well-Known Member
Most Helpful Member
Hi Ian,
I have not tried your code, but I will.

I have the DS3231 RTC working OK, time set/read, temperature etc,,, with the PIC's I2C internal module OK, its the Oshonsoft low level thats a pain.

That code I pasted is from the Oshonsoft manual.:)
E

EDIT:
Your code works, I was able to get the result I wanted using that type of coding in previous tests I had done.
Its the Oshonsoft example/demo code that will not work, thats why I am querying it with Vladimir.
E
 
Last edited:

ericgibbs

Well-Known Member
Most Helpful Member
hi,
After a great deal of testing/trying it appears that the High level statements for I2C can apply to any pair of pins of a PIC, not just to the internal I2C module.!
The way the documentation reads is that low level statements should be used for PIC's that do not have have an internal I2C module.
I took this literally, as if I used pins other than the dedicated I2C pins I would have to use low level statements.

For other users of the DS3231 this Read on 1sec interrupt works OK.
Thanks All! :angelic:

Code:
Define I2CREAD_DELAYUS = 400 
Define I2CCLOCK_STRETCH = 10
'define the SDA and SCL channels ,  The actual internal I2C pins are PORTB.0 and B.1 which I am using for SD Cards and  radio transceivers.
Symbol sda = PORTC.1
Symbol scl = PORTC.2
'interrupt
On Low Interrupt
Save System
INTCON.TMR0IF = 0
iflag = 1
read_rtc:
I2CStart
I2CSend 0xd0  'DS3231 slave addr wr
WaitUs 10
I2CSend 0x00  'first word addr wr
I2CStop
WaitUs 10
I2CStart
I2CRead sda, scl, 0xd1, 0, secs
I2CRead sda, scl, 0xd1, 1, mins
I2CRead sda, scl, 0xd1, 2, hrs
I2CRead sda, scl, 0xd1, 3, day
I2CRead sda, scl, 0xd1, 4, date
I2CRead sda, scl, 0xd1, 5, mnth
I2CRead sda, scl, 0xd1, 6, year
I2CRead sda, scl, 0xd1, 0x11, temph
I2CRead sda, scl, 0xd1, 0x12, templ
I2CStop
TMR0 = 0xff
INTCON.TMR0IE = 1
Resume
 

languer

Active Member
Vladimir has only implemented bit banging I2C and SPI
Yeap, it has been like that since day one. If you check the LST file you will quickly realize that the MSSP registers are never touched with the Oshonsoft routines. One can always create their own PROC/FN using direct register calls.

I also stopped using the compiler for the most part. I still like the simulator, but it is so far behind in terms of device support that I use it less and less all the time. Pity, since it held such great promise.
 

ericgibbs

Well-Known Member
Most Helpful Member
hi lanquer,
Have you had a chance to try the SD Card sim IDE of Oshonsoft.?

I can get the Block statements to write/read OK.
The FAT16 and FAT32 statements work OK ,with the exception of the FileAppend and FileExist statements.
A PC, SD Card reader slot can read the Oshonsoft FAT's OK and a Formatter program off the web is available.

To use FAT the PIC must have at least 1024 RAM Bytes, I use a 18F2550 off the shelf.

Sent a bug report to Vladimir, he suggested I download the latest versions, which I already had! also to make sure I had sufficient decoupling on my circuit!!
How he considers that would only effect Append and Exist when every other statements works OK is puzzling.
Also in I2C and assembler the circuit boards work OK.

My intention was to continue postings/blogs that used only Oshonsoft basic, so that other users could benefit, rather than try to decipher the OSH manuals.

Eric
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading

 
Top