jlangholzj
New Member
Alright guys, Just got my hands on a picaxe. They seemed like a pretty cool little unit and can do a lot when I don't need the umpf of a ARM core processor.
Little background:
Not a complete hardware idiot but embedded design is def. one of my weak points. I can code up and down all day in multiple languages but getting ports set up and some of the intricies of protocols can trip me up sometimes.
What I'm working with:
MLX90615 IR temp sensor
picaxe 18m2+
Data Sheet for the IR temp
The good:
Pic is working great, made lights go blinky....programs great...etc
NOW onto my problem.....
The IR sensor is smbus which from my understanding is compatible with i2c at rates lower than 100k. I've also found some documentation around the intertubes that guys have in fact got the sensor to work with something like an 08 or 20 pic.
I'm not getting anything that really makes sense with my code (down there at the bottom). I'm not entirely sure though about the i2c protocols and my scope isn't giving me something that makes sense. Mainly, I'm not entirely sure if I need to wait for the ACK from the device or not....some other things.
My main question is what address exactly I'm going to want to send for various commands. The object temp is at address $07 but in order to access rom the command needs to be 0010 aaaa based on the datasheet, giving me a $27 for the address. I'm ASSUMING that this is the address that I need to use for the hi2cin command instead of the slave address (default is something like $B4)
Which leads me to my next question, since you can have multiple devices on the buss...that would lend itself to wanting to access the slave address ($B4) instead of the ROM address command ($27). Soooo......So i need to write first, then read on the i2c buss? write to tell it the instruction at the given slave address and then read for the response that the slave is sending?
sorry if this doesn't make a whole lot of sense....lets see if this can fijure it out.
Little background:
Not a complete hardware idiot but embedded design is def. one of my weak points. I can code up and down all day in multiple languages but getting ports set up and some of the intricies of protocols can trip me up sometimes.
What I'm working with:
MLX90615 IR temp sensor
picaxe 18m2+
Data Sheet for the IR temp
The good:
Pic is working great, made lights go blinky....programs great...etc
NOW onto my problem.....
The IR sensor is smbus which from my understanding is compatible with i2c at rates lower than 100k. I've also found some documentation around the intertubes that guys have in fact got the sensor to work with something like an 08 or 20 pic.
I'm not getting anything that really makes sense with my code (down there at the bottom). I'm not entirely sure though about the i2c protocols and my scope isn't giving me something that makes sense. Mainly, I'm not entirely sure if I need to wait for the ACK from the device or not....some other things.
My main question is what address exactly I'm going to want to send for various commands. The object temp is at address $07 but in order to access rom the command needs to be 0010 aaaa based on the datasheet, giving me a $27 for the address. I'm ASSUMING that this is the address that I need to use for the hi2cin command instead of the slave address (default is something like $B4)
Which leads me to my next question, since you can have multiple devices on the buss...that would lend itself to wanting to access the slave address ($B4) instead of the ROM address command ($27). Soooo......So i need to write first, then read on the i2c buss? write to tell it the instruction at the given slave address and then read for the response that the slave is sending?
sorry if this doesn't make a whole lot of sense....lets see if this can fijure it out.
Code:
'Program to read from IR sensor
'SDSU FSAE
'Written by John Langholz
'MLX90615
init:
'symbols and defines
symbol ir_lo = b0
symbol ir_hi = b1
symbol ir_pec = b2
symbol slave_addr = b3
symbol temp = w2 ;b4 and b5
'initialize i2c communications
slave_addr = $B4 ;standard is $B4 but all respond to $00
hi2csetup i2cmaster, slave_addr, i2cslow, i2cbyte ;Set up the i2c protocols 10110100
main:
hi2cin $27, (ir_lo, ir_hi, ir_pec) ;read out of ram at location $07
temp = ir_hi*255 + ir_lo ;shift and add for the full word
temp = temp*2 - 27315 ;convert into *C
SerTxD ("Temp = ", #temp, 13, 10) ;temp output shifted 2 dec left
pause 10 ;wait to update temp set at 100Hz logging rate
goto main