Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

apds 9930

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 69

poland.gif
PostPosted: Mon Oct 01, 2018 8:19 am    Post subject: apds 9930 Reply with quote

Hello,

I'm looking for someone who did try or still is struggling to write (in bascom of course) a program for apds 9930. It is gesture/light ambient/proximity wonderful device. So far I can read datas from registers but for some reason I cannot write to registry. Let say if there are registers:

0x00 Enable - register1 Write/Read
0x01 Atime - register 2 W/R
0x02 Wtime - register 3 W/R

and I do a (pseudo) code:

Code:

 Addr_write=&H72 'according to the manual address=39hex
 Addr_read=&H73
 
 i2cinit

  i2cstart
   i2cwbyte Addr_write
   i2wbyte register1
   i2cwbyte value_to_register1
  i2cstop

  i2cstart
   i2cwbyte Addr_write
   i2wbyte register2
   i2cwbyte value_to_register2
  i2cstop
 


always I write into first register only. Second and others (above register1) are unchanged.

Martin

(BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.8.1 )
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1827

blank.gif
PostPosted: Mon Oct 01, 2018 4:43 pm    Post subject: Re: apds 9930 Reply with quote

krolikbest wrote:
wonderful device

Still wonderful, if it don't accept writes? Very Happy
Code:
   i2cwbyte Addr_write
   i2cwbyte register1
 

It's not sufficient to send the register address, you need to form a command, which consists of CMD - TYPE - ADD, see the data sheet.
ADD is actually your register address, TYPE is the form of following up data transfers and CMD is simply bit 7 set to 1.

An example to adress ATIME:
Code:
Const APDS_CMD_repByte = &h80 Or &h00
Const APDS_CMD_autoInc = &h80 Or &h20
Const APDS_CMD_specFunc = &h80 Or &h60
Const APDS_ATIME = &h01
Dim APDS_Command As Byte
APDS_Command = APDS_CMD_repByte OR APDS_ATIME
' now send to I2C
 


Last edited by MWS on Mon Oct 01, 2018 9:59 pm; edited 2 times in total
Back to top
View user's profile
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 69

poland.gif
PostPosted: Mon Oct 01, 2018 5:44 pm    Post subject: Reply with quote

Ok, I get it. After your explanation datasheet seems very clear now. As a proof attach reading id number

Code:

 I2cstart
  I2cwbyte Addr_w 'slave i2c addres
  I2cwbyte &HB2    'CMD+type+register => register=12 (i2c address)

 I2cstart
  I2cwbyte Addr_r

  I2crbyte idNum , NAck
 I2cstop
 Print  Hex(idNum)
 


Thank you,

Martin
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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
You cannot attach files in this forum
You cannot download files in this forum