test:HI2cSetupI2CMASTER,$60,I2C,I2CBYTE'I2CcommstoPIC16F628Aletb20=10hi2cout0,(b20)hi2cin(b21)sertxd(cr,cr,"Returned from 16F628A: ",#b21,cr,cr,lf)gototest
I have scope on Pin 7 and 10 give no signals.
I have analyser on the bus nothing.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Part of your CODE is incorrect. Try Copy/Paste this:
test:HI2cSetupI2CMASTER,$60,I2CFAST,I2CBYTE'I2CcommstoPIC16F628Aletb20=10hi2cout(b20)hi2cin(b21)sertxd(cr,cr,"Returned from 16F628A: ",#b21,cr,cr,lf)gototest
Regards,
Morty.
Last edit: Morty 2020-05-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK. This should work. This is HIGHLY sensitive to the amount of time between the OUT and IN in the PICAXE. I would add a delay to allow the SLAVE to do the work.
Please send beer.
;----- ProgramdoifI2CStartOccurredthen;wait for Start signalI2CReceive(addr);then wait for an addressifI2CMatch=truethen;if it matches, proceedI2CReceive(value)'do stuff here.... at the MASTER end... put a delay to enable processingvalue=value*5waitwhileI2C_CLOCK=0;wait for transitionI2CReceive(addr);and the read addressI2CSendvalue, NAK;and send the valueI2CStopendifendifloop
PICAXE
pullup%0001111100111110setfreqm32HI2cSetupI2CMASTER, $60, i2cslow_32, I2CBYTE'I2C comms to PIC16F628Aletb20=1test:
hi2cout(b20)'add a delay... would really helphi2cin(b21)sertxd(cr,cr,"Returned from 16F628A: ",#b21,cr,cr,lf)b20=b20+1ifb20>25thenb20=1endifgototest
Morty the root cause from my examination is the PICAXE is following Clock stretching. The Slave should be able to hold the Clock line low to prevent the Master transmitting but this does not happen with the PICAXE.
And, I like this code better... Whilst the Slave is waiting for the Slave Read Address the clock is monitored wait while I2C_CLOCK =0 then this version checks the Slave Read Address has been received. Should work a tad better.
Evan
;----- Variables
dim addr, reg, value as byte
;----- ProgramdoifI2CStartOccurredthen;wait for Start signalI2CReceive(addr);then wait for an addressifI2CMatch=truethen;if it matches, proceedI2CReceive(value)'do stuff here....value=value+1waitwhileI2C_CLOCK=0;wait for transitionI2CReceive(addr);and its addressif(addrOR1)=(I2C_ADDRESSOR1)thenI2CSendvalue, NAKendifI2CStopendifendifloop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Whoa! Thanks for the effort Evan, very much appreciated. Where do I send the beer mate?
Copy/Paste both sets of code however I still constantly return 255.
Did I have the correct ADDRESS in both sets of CODE?
The two complete sets of CODE:
PICAXE 20X2:
'pullup %0001111100111110 <<<COMMENTED OUT, PRESUMED PULLUPS FOR I2Csetfreqm32HI2cSetupI2CMASTER, $60, i2cslow_32, I2CBYTE'I2C comms to PIC16F628Aletb20=1test:
hi2cout(b20)'add a delay... would really helppause100' <<<DELAY ADDED HEREhi2cin(b21)sertxd(cr,cr,"Returned from 16F628A: ",#b21,cr,cr,lf)b20=b20+1ifb20>25thenb20=1endifgototest
16F628A:
;----- Configuration
#chip16F628A
#defineI2C_MODESlave;this is a slave device now
#defineI2C_CLOCKportb.2;SCL on pin 8
#defineI2C_DATAportb.1;SDA on pin 7
#defineI2C_ADDRESS0x60;address of the slave device;----- Variablesdimaddr, valueasbyte;----- ProgramdoifI2CStartOccurredthen;wait for Start signalI2CReceive(addr);then wait for an addressifI2CMatch=truethen;if it matches, proceedI2CReceive(value)'do stuff here.... at the MASTER end... put a delay to enable processingvalue=value*5waitwhileI2C_CLOCK=0;wait for transitionI2CReceive(addr);and the read addressI2CSendvalue, NAK;and send the valueI2CStopendifendifloop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You will need to run the 16F628a at 16mhz with an external clock to make this work.
So, #chip 16f628a, 16 (with external OSC) and you will have to drop the PICAXE to m4 and i2cslow_4. Something is totally ignoring clock stretching........
I was testing here at 32 mhz on the my 16f slave, if I drop to 4mhz or 8mhz [these are internal clocks)... I get 255. Set to 16mhz.... all ok.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
PICAXE connected via I2C bus with suitable pullup resistors. The I2C Slave address is 0x60. The frequency of the PICAXE is critical. .
The PICAXE Master sends a value to the Slave and the Slave returns the value with 1 added to it.
Enjoy
Final code:
PICAXE CODE
'i2C Master with external PIC Slave'Frequency of PIXACE is CRITICAL'This is has been tested to interoperate with a PIC at 4mHz'setfreqm1letb20=1test:
HI2cSetupI2CMASTER, $60, i2cslow_4, I2CBYTE'I2C comms to PIC16F628Ahi2cout(b20)pause10'This delay is required, it gives time for the Slave to process stuff.hi2cin(b21)sertxd(cr,cr,"Returned from PIC: ",#b21,cr,cr,lf)b20=b20+1ifb20=25thenb20=0endifpause500gototest
Great Cow BASIC PIC CODE
'change the chip...
#chip16F15376, 4
#defineI2C_MODESlave;this is a slave device now
#defineI2C_CLOCKportd.1
#defineI2C_DATAportd.0
#defineI2C_ADDRESS0x60;address of the slave device;----- Variablesdimaddr, reg, valueasbytewait1s;----- ProgramdoifI2CStartOccurredthen;wait for Start signalI2CReceive(addr);then wait for an addressifI2CMatch=truethen;if it matches, proceedI2CReceive(value)'do stuff here.... whlist the PICAXE is waiting....value=value+1'end of do stuff.....waitwhileI2C_CLOCK=0;wait for transitionI2CReceive(addr);and its addressif(addrOR1)=(I2C_ADDRESSOR1)then;check it is the read addressI2CSendvalue, NAK;send the dataendifI2CStopendifendifloop
Last edit: Anobium 2020-05-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, I meant same as the 20X2.
Funnily enough I also have a AXE091 dev board, but I practically never use it as I just completely create what I need with breadboards.
Regards,
Morty.
This code generates NO I2C bus communications.
I have scope on Pin 7 and 10 give no signals.
I have analyser on the bus nothing.
Part of your CODE is incorrect. Try Copy/Paste this:
Regards,
Morty.
Last edit: Morty 2020-05-01
Nothing on the I2C bus - and, therefore I get 255 on the PICAXE terminal
Here is some CODE with the PIC16F628 & LTC2485 on the same bus.
Attached is what is returned.
Regards,
Morty.
OK. This should work. This is HIGHLY sensitive to the amount of time between the OUT and IN in the PICAXE. I would add a delay to allow the SLAVE to do the work.
Please send beer.
PICAXE
Gives this...
Last edit: Anobium 2020-05-01
Morty the root cause from my examination is the PICAXE is following Clock stretching. The Slave should be able to hold the Clock line low to prevent the Master transmitting but this does not happen with the PICAXE.
And, I like this code better... Whilst the Slave is waiting for the Slave Read Address the clock is monitored
wait while I2C_CLOCK =0
then this version checks the Slave Read Address has been received. Should work a tad better.Evan
;----- Variables
dim addr, reg, value as byte
Whoa! Thanks for the effort Evan, very much appreciated. Where do I send the beer mate?
Copy/Paste both sets of code however I still constantly return 255.
Did I have the correct ADDRESS in both sets of CODE?
The two complete sets of CODE:
PICAXE 20X2:
16F628A:
You will need to run the 16F628a at 16mhz with an external clock to make this work.
So, #chip 16f628a, 16 (with external OSC) and you will have to drop the PICAXE to m4 and i2cslow_4. Something is totally ignoring clock stretching........
I was testing here at 32 mhz on the my 16f slave, if I drop to 4mhz or 8mhz [these are internal clocks)... I get 255. Set to 16mhz.... all ok.
Just tried to get 4mhz/8mhz working... nope.
You can make the 16F628a at internal 4mhz with
setfreq m1
withi2cslow_4
will force the I2C clock to 25khz which works!!PICAXE connected via I2C bus with suitable pullup resistors. The I2C Slave address is 0x60. The frequency of the PICAXE is critical. .
The PICAXE Master sends a value to the Slave and the Slave returns the value with 1 added to it.
Enjoy
Final code:
PICAXE CODE
Great Cow BASIC PIC CODE
Last edit: Anobium 2020-05-01
This has now been resolved.
Thanks again.
Regards,
Morty.