Newbie here. I came across GCB trying to find a way I can program PIC's with BASIC. Boy... Did I strike gold here or what!!! Excited to come across this platform.
Anywayz, I have come from the land of PICAXE and am reasonably fluent nowdays, but a total noob around these parts.
I have viewed many videos in just a few days and I am now here looking to communicate to a 16F628A as a slave from a PICAXE 20X2 master.
However from what I can gather, it is rather incomplete for noobs to fully grasp.
It would have been greatly beneficial if the gentleman had shown the entire code and/or provided a link to the complete code example. I am uncertain with some of the variables.
Essentially I am currently looking to send 4 bytes (32bits) across I2C to the PIC16F628A from a PICAXE20X2, do some number crunching, and return a 16bit word result from the calculations.
From what I read around here, it should be quite easy,. But I be buggered if I can get it to compile, let alone. function as I want.
ANY help would be greatly appreciated.
P.S. I have accidently posted this same query under 'Great Cow Graphical BASIC Problems' if an Admin could possibly remove that post.
Regards,
mortify-u
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Firstly, welcome. I came from PICAXE a while ago. This is good fun but forget the constraints you had - you have the freedom to use the full capabilities of the PIC.
Questions.
Those chips. What are the real part names? 16F?????? . With this info I can tell you why it may not compile.
Why I2C? Why not a robust serial ring buffer?
Got the latest version of the Great Cow BASIC tools?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This post is the second/correctly placed post. Please remove the other post if you can.
PICAXE20X2 = PIC18F14K22-I/P
I need to use I2C because I need to add the PIC16F628A to an existing circuit/system.
I believe I have the latest versions of everything GCB.
If I am not mistaken, you are the man to whom posted the I2C video in question. Great to meet you mate. Your video appeared to do roughly what I want to do, but I was unable to view the entire code of that exercise. Could you please possibly post the complete code here?
Regards,
Morty.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using software I2C was the route I was looking at.
I don't have anymore 18F's on hand and the 16F628A was one I just happened to have here.
For the purpose of getting this to work today as I am hoping, I'd like to stick with the chips I am currently using, but can indeed get another one at a later date.
I suspect the 16F628A is miles 'over the top' for what I am doing, but will do for now. I am realistically using it as an I2C interfaced math co-processor. Doing this via software will get me on the ground running with GCB.
The 4 bytes (32bits) being sent from the PICAXE will need bits 6 to 29 (24bit value) extracted and used in a calculation with the end result being a 1 word (16bit) value being returned to the PICAXE. This 24bit value has originally come from a LTC2485 24bit ADC.
Regards,
Morty.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK. Then, software I2C is the route to go. [Context... PICAXE was software I2C using Bit-Banging]
Look at I2CReceive in the Help. You are creating a Slave - so, look at the second code example. You will need wait (as on the code) then hold the clock line low (to stretch the I2C communications) do your maths and then send a value back.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Compiles OK, but still no comms...
I am sure this is so simple...
Where am I going wrong?
PICAXE CODE:
test:
HI2cSetup I2CMASTER, $60, I2CFAST, I2CBYTE 'I2C comms to PIC16F628A
let b20=10
hi2cout 0,(b20)
hi2cin (b21)
sertxd(cr,cr,"Returned from 16F628A: ",#b21,cr,cr,lf)
goto test
GCB CODE:
`#chip 16F628A
#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, reg, valueasbyte;----- ProgramdoI2CStart;wait for Start signalI2CReceive(addr);then wait for an addressifI2CMatch=truethen;if it matches, proceedI2CReceive(regval, ACK);get the register numberI2CReceive(value, ACK);and its value'My math routine will go herePulseOutporta.2, 1000msvalue=value*10I2CSendvalueI2CStop;release the bus from this endelseI2CStop;release bus in any eventendifloop`
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Certainly do. 4K7 in both cases. There is also an LCD on the same I2C bus, and it is working fine.
To me it seems the 16F628A is just not taking notice of the command sent from the PICAXE.
I am sure I have the addressing correct.
I have now just tried I2CSLOW in the PICAXE program to see if that made any difference and now 97 is being returned. So I would imagine the communications are right now. However, why is it returning 97 instead of 100?
Essentially I am sending a value of 10, multiplying it by 10 in the 16F628A and then sending the result back which obviously should be 100. Not sure where 97 is coming from? Strange.
Regards,
Morty.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am not getting a result back because the slave is not responding. Not sure why. I did not write these libraries as I only use the hardware I2C. Need to resolve why the slave is NOT responding with an ACK.
Ok. So where does this leave me? The need to get another PIC with hardware I2C?
As this is a pretty simple and small task I am trying to achieve, is there perhaps a suitable 8pin PIC?
The calculations I require run into the millions. With a 16F628A I did a little experimental test that worked fine which just left me with the dilemma of I2C comms to deal with.
Master - PICAXE20X2/PIC18F14K22-I/P
LCD - 20x4
LTC2485 - 24bit ADC
+
16F628A - To be a math co-processor
The first 3 components are working fine together, however with such large numbers it has proven very difficult to do the math with the PICAXE hence the addition of the 16F628A.
Regards,
Morty.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
;----- Variablesdimaddr, reg, valueasbyte;----- ProgramdoifI2CStartOccurredthen;wait for Start signalI2CReceive(addr,ack);then wait for an addressifI2CMatch=truethen;if it matches, proceedI2CReceive(value);and its value'My math routine will go herevalue=value*10I2CSendvalueendifendifloop
main:
HI2cSetupI2CMASTER, $60, I2CFAST, I2CBYTE'I2C comms to PIC16F628Aletb20=10hi2cout0,(b20)hi2cin(b21)sertxd(cr,cr,"Returned from 16F628A: ",#b21,cr,cr,lf)pause1000gotomain
16F628A
#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,ack);then wait for an addressifI2CMatch=truethen;if it matches, proceedI2CReceive(value);and its value'My math routine will go herevalue=value*10I2CSendvalueendifendifloop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am guessing. I guess the hi2cin (b21) is a read on 0x61.
Can you write me a PICAXE program for an 18M2? I have an AXE091. I need a program that I test. I need to know what pins the 18M2 uses for SDA and SCL (I am not hunting for this info). I need to see what PICAXE actaully does on the I2C bus. I dont like flying in the blind.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello ALL,
Newbie here. I came across GCB trying to find a way I can program PIC's with BASIC. Boy... Did I strike gold here or what!!! Excited to come across this platform.
Anywayz, I have come from the land of PICAXE and am reasonably fluent nowdays, but a total noob around these parts.
I have viewed many videos in just a few days and I am now here looking to communicate to a 16F628A as a slave from a PICAXE 20X2 master.
I viewed this video attempting to understand...
https://www.youtube.com/watch?v=Qu8xWAQaJm4
However from what I can gather, it is rather incomplete for noobs to fully grasp.
It would have been greatly beneficial if the gentleman had shown the entire code and/or provided a link to the complete code example. I am uncertain with some of the variables.
Essentially I am currently looking to send 4 bytes (32bits) across I2C to the PIC16F628A from a PICAXE20X2, do some number crunching, and return a 16bit word result from the calculations.
From what I read around here, it should be quite easy,. But I be buggered if I can get it to compile, let alone. function as I want.
ANY help would be greatly appreciated.
P.S. I have accidently posted this same query under 'Great Cow Graphical BASIC Problems' if an Admin could possibly remove that post.
Regards,
mortify-u
Morning Morty (Is this a second post?)
Firstly, welcome. I came from PICAXE a while ago. This is good fun but forget the constraints you had - you have the freedom to use the full capabilities of the PIC.
Questions.
Those chips. What are the real part names? 16F?????? . With this info I can tell you why it may not compile.
Why I2C? Why not a robust serial ring buffer?
Got the latest version of the Great Cow BASIC tools?
Hello, thanks for the quick response.
This post is the second/correctly placed post. Please remove the other post if you can.
PICAXE20X2 = PIC18F14K22-I/P
I need to use I2C because I need to add the PIC16F628A to an existing circuit/system.
I believe I have the latest versions of everything GCB.
If I am not mistaken, you are the man to whom posted the I2C video in question. Great to meet you mate. Your video appeared to do roughly what I want to do, but I was unable to view the entire code of that exercise. Could you please possibly post the complete code here?
Regards,
Morty.
The root cause is pretty simple.
The 16F628A does not support hardware I2C with the required interrupts. The library relies on specific I2C capabilities which that chip does not have.
What route do you want to go?
Using software I2C was the route I was looking at.
I don't have anymore 18F's on hand and the 16F628A was one I just happened to have here.
For the purpose of getting this to work today as I am hoping, I'd like to stick with the chips I am currently using, but can indeed get another one at a later date.
I suspect the 16F628A is miles 'over the top' for what I am doing, but will do for now. I am realistically using it as an I2C interfaced math co-processor. Doing this via software will get me on the ground running with GCB.
The 4 bytes (32bits) being sent from the PICAXE will need bits 6 to 29 (24bit value) extracted and used in a calculation with the end result being a 1 word (16bit) value being returned to the PICAXE. This 24bit value has originally come from a LTC2485 24bit ADC.
Regards,
Morty.
OK. Then, software I2C is the route to go. [Context... PICAXE was software I2C using Bit-Banging]
Look at
I2CReceive
in the Help. You are creating a Slave - so, look at the second code example. You will need wait (as on the code) then hold the clock line low (to stretch the I2C communications) do your maths and then send a value back.Thanks for the tips. I thought I went down that road, but will go over it again carefully.
Also thank you very much for the huge tip of holding the clock line low to stretch the I2C comms.
For the sake of the forum, I'll come back here and let you know how I went and if there was any other issues.
Regards,
Morty.
Compiles OK, but still no comms...
I am sure this is so simple...
Where am I going wrong?
PICAXE CODE:
test:
HI2cSetup I2CMASTER, $60, I2CFAST, I2CBYTE 'I2C comms to PIC16F628A
let b20=10
hi2cout 0,(b20)
hi2cin (b21)
sertxd(cr,cr,"Returned from 16F628A: ",#b21,cr,cr,lf)
goto test
GCB CODE:
`#chip 16F628A
This code is waiting for two values from the master.
You are sending one value. So, remove the following.
Thanks for that. I suspected that was what the 2x I2CReceive lines were suggesting.
I removed
I2CReceive(regval, ACK) ;get the register number
But there is no change.
The PICAXE is displaying
255
as a returned value. Obviously not getting anything back.Regards,
Morty.
Got an analyser?
Got pullsup on the SDA/SCL ?
No I don't. Hence why I put the
PulseOut
line in there which has an LED attached to it.I have confirmed it is processing by placing the
PulseOut
line immediately afterdo
By this, the LED does flash.
Regards,
Morty.
Certainly do. 4K7 in both cases. There is also an LCD on the same I2C bus, and it is working fine.
To me it seems the 16F628A is just not taking notice of the command sent from the PICAXE.
I am sure I have the addressing correct.
I have now just tried I2CSLOW in the PICAXE program to see if that made any difference and now 97 is being returned. So I would imagine the communications are right now. However, why is it returning 97 instead of 100?
Essentially I am sending a value of 10, multiplying it by 10 in the 16F628A and then sending the result back which obviously should be 100. Not sure where 97 is coming from? Strange.
Regards,
Morty.
Sorry, no I just repowered the circuit and it still returns 255. 97 Must have been some noise from the programming phase.
Regards,
Morty.
And the LED is NOT pulsing as I would hope.
Regards,
Morty.
This is what the code is generating from the Master. Which from a protocol state looks ok. But, the slave is not responding.
I am using Software I2C on the Master.
This is the code I2C protocol. Trust me. Picaxe may not have followed the protocol.
I am not getting a result back because the slave is not responding. Not sure why. I did not write these libraries as I only use the hardware I2C. Need to resolve why the slave is NOT responding with an ACK.
Ok. So where does this leave me? The need to get another PIC with hardware I2C?
As this is a pretty simple and small task I am trying to achieve, is there perhaps a suitable 8pin PIC?
The calculations I require run into the millions. With a 16F628A I did a little experimental test that worked fine which just left me with the dilemma of I2C comms to deal with.
Last edit: Morty 2020-05-01
I should also note that on this I2C bus there is:
Master - PICAXE20X2/PIC18F14K22-I/P
LCD - 20x4
LTC2485 - 24bit ADC
+
16F628A - To be a math co-processor
The first 3 components are working fine together, however with such large numbers it has proven very difficult to do the math with the PICAXE hence the addition of the 16F628A.
Regards,
Morty.
Some working code. Not use the SW I2C for receive.
Master sends values 1 to 10, slave factors and the terminal shows the factored numbers.
Works ok... May update the Help!
Master
Slave
Hmmm.. Interesting.
This is what I have now done, but still no joy...
PICAXE 20X2
16F628A
The read address is 0x61, that is the standard not a Great Cow BASIC rule . Change and test.
HI2cSetup I2CMASTER, $61, I2CFAST, I2CBYTE 'I2C comms to PIC16F628A
This error occurred.
So I tried:
PICAXE 20X2
16F628A
This didn't work. But have I done the correct change? I thought it was to be a 7-bit address?
Regards,
Morty.
I am guessing. I guess the
hi2cin (b21)
is a read on 0x61.Can you write me a PICAXE program for an 18M2? I have an AXE091. I need a program that I test. I need to know what pins the 18M2 uses for SDA and SCL (I am not hunting for this info). I need to see what PICAXE actaully does on the I2C bus. I dont like flying in the blind.
The CODE for 18M2 is exactly the same for 08M2. Within PE6 they both PASS Syntax Check.
Attached is the PINOUTS of a 18M2 if that helps.
Regards,
Morty.