For many years (2001) I used PicBasicPro and until yesterday I used PBP3 which was perfect for my projects. Now I've been to Swordfish and I'm converting PBP3 programs into Swordfish
Swordfish is more powerful and more suitable for my new exegesis, in mariculture math is very interesting. Unfortunately I have encountered some obstacles to the use of I2C libraries for now.
Read data in to device from the Microchip ADC MCP3421, by I3C bus:
a) Old PBP3 instruction code that works perfectly
I2Cread sda, scl, $D5, [B3,B2,B1,B0]
b) New code education in Swordfish:
Dim B0, B1, B2, B3 As Byte
I2C.Start
I2C.WriteByte($D5)
B3 = I2C.ReadByte
I2C.Acknowledge(I2C_NOT_ACKNOWLEDGE)
B2 = I2C.ReadByte
I2C.Acknowledge(I2C_NOT_ACKNOWLEDGE)
B1 = I2C.ReadByte
I2C.Acknowledge(I2C_NOT_ACKNOWLEDGE)
B0 = I2C.ReadByte
I2C.Acknowledge(I2C_NOT_ACKNOWLEDGE)
I2C.Stop
It's correct?
Thanks
Umberto
I2C from PBP3 to Swordfish (no EEprom)
Moderators: David Barker, Jerry Messina
-
- Swordfish Developer
- Posts: 1470
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: I2C from PBP3 to Swordfish (no EEprom)
When you read you want the master to ACK every byte but the last, so it should look more like
There's also a form of ReadByte that will take care of this for you
Code: Select all
Dim B0, B1, B2, B3 As Byte
I2C.Start
I2C.WriteByte($D5)
B3 = I2C.ReadByte
I2C.Acknowledge(I2C_ACKNOWLEDGE)
B2 = I2C.ReadByte
I2C.Acknowledge(I2C_ACKNOWLEDGE)
B1 = I2C.ReadByte
I2C.Acknowledge(I2C_ACKNOWLEDGE)
B0 = I2C.ReadByte
I2C.Acknowledge(I2C_NOT_ACKNOWLEDGE)
I2C.Stop
Code: Select all
Dim B0, B1, B2, B3 As Byte
I2C.Start
I2C.WriteByte($D5)
B3 = I2C.ReadByte(I2C_ACKNOWLEDGE)
B2 = I2C.ReadByte(I2C_ACKNOWLEDGE)
B1 = I2C.ReadByte(I2C_ACKNOWLEDGE)
B0 = I2C.ReadByte(I2C_NOT_ACKNOWLEDGE)
I2C.Stop
Re: I2C from PBP3 to Swordfish (no EEprom)
Thank you very much