|
|
View previous topic :: View next topic |
Author |
Message |
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
amg88, how to read |
Posted: Sat May 20, 2017 11:45 am |
|
|
Hi guys
I try to make a amg8853 sensor work with pic18f2550. Actually the problem is more generic. Can anyone tell me how to use i2c_write and read comands to get bytes from address 0x80 up to 0x100 ? I can't find much info. I try to convert 2416.c driver but with no luck. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1941 Location: Norman, OK
|
|
Posted: Sat May 20, 2017 12:10 pm |
|
|
I think you are ahead of things a bit.
- What voltage are you using?
- Which I2C address are you using?
- Is the address pin set properly? (AD_Select)
- How do you know you can properly communicate with the device?
The best place to start is with the I2C bus scanner program at
the top of the Code Library to see if you can locate the device on
the bus at one of the two addresses.
Here is more info on the GridEye registers and addressing
https://eewiki.net/display/Motley/Panasonic+Grid+Eye+Memory+Registers#PanasonicGridEyeMemoryRegisters-I2CSlaveAddress _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Sat May 20, 2017 12:34 pm |
|
|
The device addresses are 0xD2, and 0xD3. (Write/read).
Before doing anything else, run the I2C bus scanner program from the code library, and verify your device is seen. If it isn't you have a connection problem...
You need to understand the difference between the I2C address and the register address:
Code: |
#define AMGREAD 0xD3
#define AMGWRITE 0xD2
void amg_write_byte(int8 address, int8 val)
{
//write a single byte to the AMG register 'address'
i2c_start();
i2c_write(AMGWRITE);
i2c_write(address);
i2c_write(val);
i2c_stop();
}
int16 amg_read_pixel(int8 address)
{
//read a word from the pixel 0 to 63
int16 result;
int8 temp;
temp=address*2+0x80;
i2c_start();
i2c_write(AMGWRITE);
i2c_write(temp);
//now restart
i2c_start();
i2c_write(AMGREAD);
temp=i2c_read(); //read the first byte from address
result=make16(i2c_read(0),temp); //nack the second byte
i2c_stop();
return result;
}
|
Now you will need to use the write code to configure the chip. First select normal mode, and reset, then switch to frame mode and specify the rate.
Once it is configured, then read the 16bit words from the chip pixel array.
Hopefully you have the Panasonic full data, not just the basic data sheet?. You need it.
Updated -
Refer below to a block read routine - much more efficient.
Last edited by Ttelmah on Sun May 21, 2017 1:18 am; edited 2 times in total |
|
|
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
|
Posted: Sat May 20, 2017 1:05 pm |
|
|
Thank you! No I don't have a proper datasheet. I was trying to understand by Arduino libraries what is the flow, but I have never played with Arduino so I was trying by test. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Sun May 21, 2017 12:39 am |
|
|
Honestly without proper data, you will find it hard. Go to the Panasonic site, and register. There are two sheets (the overview one that gives dimensions and electrical figures etc. - this is available without registration), and one describing the registers/protocol. There is also some example code available from them.
Then also get the I2C specification document. You then have a hope of understanding how things work.
If you look here:
Quote: |
<https://shop.mikroe.com/click/sensors/grid-eye>
|
Their 'I2C_init(100000)' command is like #use i2c, specifying 100KHz bus rate (you can actually go to 400000 here).
Their GridEye_WriteByte command is like my amg_write_byte command. With the register number, and the value to be sent.
Their GridEye_ReadWord command is like my 'amg_read_pixel' command, but mine generates the register address from a pixel number.
It's worth saying possibly that the fastest way to read the data, is to do a block read, not the individual pixel read (depends what you actually want to do). So:
Code: |
void amd_read_array(int16 * array)
{
//read the whole pixel array
int8 temp, ctr=0;
i2c_start();
i2c_write(AMGWRITE);
i2c_write(0x80); //location of the pixel array in the chip
i2c_start();//restart
i2c_write(AMGREAD); //and read command
do
{
//now loop 64 times
temp=i2c_read(); //read the first byte from address
if (ctr==63)
array[ctr++]=make16(i2c_read(0),temp); //nack the last byte only
else
array[ctr++]=make16(i2c_read(),temp);
} while (ctr<64);
i2c_stop();
return result;
}
//Then in your main code
int16 data[64]; //array for 64 pixels
//and after initialisation etc..
amd_read_array(data); //read the whole 128 bytes
|
This then only does the start, and address transmission on the first byte, and just does a block read of the bytes. Potentially a lot faster.
As a comment, you will also need to 'sign extend' to the PIC int16. A search here will find previous examples where I have shown how to do this. The chip only returns 12bit data, and to use this correctly as 'signed', you will have to read bit 11, and if this is set, set bits 12,13,14 & 15 in the value stored.
Doesn't apply if you are always using +ve values, but if you want to handle -ve values this will need to be done (and the array declared as 'signed int16' as well). |
|
|
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
|
Posted: Sun May 21, 2017 3:33 am |
|
|
I did find the documentation from other source but without lesson like yours, it would be hard. I think their datasheet lacks of information. Thank you again. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|