درود مهندسان گرامی
من یه ماژول apds9930 دارم که از طریق I2c باید مقادیرشو بخونم منم دست و پا شکسته با بسکام میتونم کار کنم میکرومم مگا 8 هستش لطفا اگه کسی اطالاعاتی داره کمک کنه راش بندازم
من با توجه به هلپ بسکام و چند تا نمونه برنامه سعی کردم ولی نتیجه ایی نداشت
رجیستری که مقدارش مهمه همونه که تو دیتاشیت با کد 0x18 , 0x19 معرفی شده
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32
'Config Ports_________________________________
Config Portd.7 = Output
Config Portb.3 = Output
dim value1 as byte,value2 as byte
dim count as byte
dim Adres As Byte
config watchdog = 2048
start watchdog
'Config LCD_________________________________
Config Lcdpin = Pin , Db4 = Pinc.3 , Db5 = Pinc.2 , Db6 = Pinc.1 , Db7 = _
Pinc.0 , E = Pinb.0 , Rs = Pinb.1
Config Lcd = 16 * 2
Cursor Off : Cls
count =0
Config Sda = Portc.4
Config Scl = Portc.5
Config I2cdelay = 20
Const Address_s = 0x72
Const Address_r = 0x73
Declare Sub Write_sensor(byval Adres As Byte , Byval Value2 As Byte)
Declare Sub Read_sensor(byval Adres As Byte , Value1 As Byte)
-------------------------------------------------------------------------
waitms 100
reset watchdog
I2cinit
Do
incr count
Call Read_sensor(&h18 , Value1)
waitms 500
reset watchdog
locate 1,1
lcd value1
locate 2,1
lcd value2
locate 2,9
lcd count
if count=10 then
toggle portd.7
count=0
reset watchdog
endif
waitms 200
reset watchdog
Loop
sub Read_sensor(byval Adres As Byte , Value1 As Byte)
I2cstart 'generate start
I2cwbyte Address_s 'slave adsress
I2cwbyte Adres 'address of EEPROM
I2cstart 'repeated start
I2cwbyte Address_r 'slave address (read)
I2crbyte Value1 , Nack 'read byte
I2cstop 'generate stop
End Sub
End
تو دیتاشیتش هم 2 قسمت مرتبط با برنامه نویسیش پیدا کردم که اینجا میزارم ببینید چیزی متوجه میشید ازش
این یه قسمتشه
اینم یه قسمت دیگش
Basic Software Operation
The following pseudo-code shows how to do basic initialization of the APDS-9930.
uint8 ATIME, PIME, WTIME, PPULSE;
ATIME = 0xff; // 2.7 ms – minimum ALS integration time
WTIME = 0xff; // 2.7 ms – minimum Wait time
PTIME = 0xff; // 2.7 ms – minimum Prox integration time
PPULSE = 1; // Minimum prox pulse count
WriteRegData(0, 0); //Disable and Powerdown
WriteRegData (1, ATIME);
WriteRegData (2, PTIME);
WriteRegData (3, WTIME);
WriteRegData (0xe, PPULSE);
uint8 PDRIVE, PDIODE, PGAIN, AGAIN;
PDRIVE = 0; //100mA of LED Power
PDIODE = 0x20; // CH1 Diode
PGAIN = 0; //1x Prox gain
AGAIN = 0; //1x ALS gain
WriteRegData (0xf, PDRIVE | PDIODE | PGAIN | AGAIN);
uint8 WEN, PEN, AEN, PON;
WEN = 8; // Enable Wait
PEN = 4; // Enable Prox
AEN = 2; // Enable ALS
PON = 1; // Enable Power On
WriteRegData (0, WEN | PEN | AEN | PON); // WriteRegData(0,0x0f);
Wait(12); //Wait for 12 ms
int CH0_data, CH1_data, Prox_data;
CH0_data = Read_Word(0x14);
CH1_data = Read_Word(0x16);
Prox_data = Read_Word(0x18);
WriteRegData(uint8 reg, uint8 data)
{
m_I2CBus.WriteI2C(0x39, 0x80 | reg, 1, &data);
}
uint16 Read_Word(uint8 reg);
{
uint8 barr[2];
m_I2CBus.ReadI2C(0x39, 0xA0 | reg, 2, ref barr);
return (uint16)(barr[0] + 256 * barr[1]);
}
من یه ماژول apds9930 دارم که از طریق I2c باید مقادیرشو بخونم منم دست و پا شکسته با بسکام میتونم کار کنم میکرومم مگا 8 هستش لطفا اگه کسی اطالاعاتی داره کمک کنه راش بندازم
من با توجه به هلپ بسکام و چند تا نمونه برنامه سعی کردم ولی نتیجه ایی نداشت
رجیستری که مقدارش مهمه همونه که تو دیتاشیت با کد 0x18 , 0x19 معرفی شده
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32
'Config Ports_________________________________
Config Portd.7 = Output
Config Portb.3 = Output
dim value1 as byte,value2 as byte
dim count as byte
dim Adres As Byte
config watchdog = 2048
start watchdog
'Config LCD_________________________________
Config Lcdpin = Pin , Db4 = Pinc.3 , Db5 = Pinc.2 , Db6 = Pinc.1 , Db7 = _
Pinc.0 , E = Pinb.0 , Rs = Pinb.1
Config Lcd = 16 * 2
Cursor Off : Cls
count =0
Config Sda = Portc.4
Config Scl = Portc.5
Config I2cdelay = 20
Const Address_s = 0x72
Const Address_r = 0x73
Declare Sub Write_sensor(byval Adres As Byte , Byval Value2 As Byte)
Declare Sub Read_sensor(byval Adres As Byte , Value1 As Byte)
-------------------------------------------------------------------------
waitms 100
reset watchdog
I2cinit
Do
incr count
Call Read_sensor(&h18 , Value1)
waitms 500
reset watchdog
locate 1,1
lcd value1
locate 2,1
lcd value2
locate 2,9
lcd count
if count=10 then
toggle portd.7
count=0
reset watchdog
endif
waitms 200
reset watchdog
Loop
sub Read_sensor(byval Adres As Byte , Value1 As Byte)
I2cstart 'generate start
I2cwbyte Address_s 'slave adsress
I2cwbyte Adres 'address of EEPROM
I2cstart 'repeated start
I2cwbyte Address_r 'slave address (read)
I2crbyte Value1 , Nack 'read byte
I2cstop 'generate stop
End Sub
End
تو دیتاشیتش هم 2 قسمت مرتبط با برنامه نویسیش پیدا کردم که اینجا میزارم ببینید چیزی متوجه میشید ازش
این یه قسمتشه
Reset Value | REGISTER FUNCTION | R/W | RESISTER NAME | ADDRESS |
0x00 | Specifies register address | W | COMMAND | |
0x00 | Enable of states and interrupts | R/W | ENABLE | 0x00 |
0xFF | ALS ADC time | R/W | ATIME | 0x01 |
0xFF | Proximity ADC time | R/W | PTIME | 0x02 |
0xFF | Wait time | R/W | WTIME | 0x03 |
0x00 | ALS interrupt low threshold low byte | R/W | AILTL | 0x04 |
0x00 | ALS interrupt low threshold hi byte | R/W | AILTH | 0x05 |
0x00 | ALS interrupt hi threshold low byte | R/W | AIHTL | 0x06 |
0x00 | ALS interrupt hi threshold hi byte | R/W | AIHTL | 0x07 |
0x00 | Proximity interrupt low threshold low byte | R/W | PILTL | 0x08 |
0x00 | Proximity interrupt low threshold hi byte | R/W | PILTH | 0x09 |
0x00 | Proximity interrupt hi threshold low byte | R/W | PIHTL | 0x0A |
0x00 | Proximity interrupt hi threshold hi byte | R/W | PIHTH | 0x0B |
0x00 | Interrupt persistence filters | R/W | PERS | 0x0C |
0x00 | Configuration | R/W | CONFIG | 0x0D |
0x00 | Proximity pulse count | R/W | PPULSE | 0x0E |
0x00 | Gain control register | R/W | CONTROL | 0x0F |
ID | Device ID | R | ID | 0x12 |
0x00 | Device status | R | STATUS | 0x13 |
0x00 | Ch0 ADC low data register | R | Ch0DATAL | 0x14 |
0x00 | Ch0 ADC high data register | R | Ch0DATAH | 0x15 |
0x00 | Ch1 ADC low data register | R | Ch1DATAL | 0x16 |
0x00 | Ch1 ADC high data register | R | Ch1DATAH | 0x17 |
0x00 | Proximity ADC low data register | R | PDATAL | 0x18 |
0x00 | Proximity ADC high data register | R | PDATAH | 0x19 |
Proximity offset register | R/W | POFFSET | 0x1E |
Basic Software Operation
The following pseudo-code shows how to do basic initialization of the APDS-9930.
uint8 ATIME, PIME, WTIME, PPULSE;
ATIME = 0xff; // 2.7 ms – minimum ALS integration time
WTIME = 0xff; // 2.7 ms – minimum Wait time
PTIME = 0xff; // 2.7 ms – minimum Prox integration time
PPULSE = 1; // Minimum prox pulse count
WriteRegData(0, 0); //Disable and Powerdown
WriteRegData (1, ATIME);
WriteRegData (2, PTIME);
WriteRegData (3, WTIME);
WriteRegData (0xe, PPULSE);
uint8 PDRIVE, PDIODE, PGAIN, AGAIN;
PDRIVE = 0; //100mA of LED Power
PDIODE = 0x20; // CH1 Diode
PGAIN = 0; //1x Prox gain
AGAIN = 0; //1x ALS gain
WriteRegData (0xf, PDRIVE | PDIODE | PGAIN | AGAIN);
uint8 WEN, PEN, AEN, PON;
WEN = 8; // Enable Wait
PEN = 4; // Enable Prox
AEN = 2; // Enable ALS
PON = 1; // Enable Power On
WriteRegData (0, WEN | PEN | AEN | PON); // WriteRegData(0,0x0f);
Wait(12); //Wait for 12 ms
int CH0_data, CH1_data, Prox_data;
CH0_data = Read_Word(0x14);
CH1_data = Read_Word(0x16);
Prox_data = Read_Word(0x18);
WriteRegData(uint8 reg, uint8 data)
{
m_I2CBus.WriteI2C(0x39, 0x80 | reg, 1, &data);
}
uint16 Read_Word(uint8 reg);
{
uint8 barr[2];
m_I2CBus.ReadI2C(0x39, 0xA0 | reg, 2, ref barr);
return (uint16)(barr[0] + 256 * barr[1]);
}
دیدگاه