News:

Let's find out together what makes a PIC Tick!

Main Menu

Trying to write I2C to CCS811 chip

Started by Gamboa, Mar 26, 2021, 05:09 PM

Previous topic - Next topic

Gamboa

Hi list,

I don't understand how I can do this protocol with the BUSIN and BUSOUT commands.

First, the form of the protocol does not match a pure I2C. To read a record (for example $ 00) you first have to write but without a parameter, which cannot be done because the compiler forces you to put the parameter.
I explain it with an example. Let's say I want to read the STATUS register (address $ 00). In the STATUS.PNG image the manufacturer puts the sequence.

Status.png

BUSOUT $B4,$00,[] (In red what is left )
BUSIN $B5,$00,[Value] (In red what is left )

I guess with this method you can't do this.

I have tried to do a test with the standalone commands:

  BSTART
  BUSOUT $B4
  BUSOUT $00
  'Brestart   (I have tried with restart and without restart )
  BUSOUT $B5
  BUSIN Value
  BSTOP

I've been doing tests for two days but they don't seem to be working.
I am doing the tests with a PIC18F24J11 and the pins are configured correctly:
 
 DECLARE SDA_PIN PORTB.3  'Defino I2C software
 DECLARE SCL_PIN PORTB.4
 DECLARE SLOW_BUS ON

If anyone has worked with something similar I would appreciate any help. I attach the device datasheet.

CCS811_Programming_Guide.pdf
Regards,
Gamboa

Long live for you

RGV250

Hi Gamboa,
I think the AHT20 code I wrote might put you on the right track.
https://protoncompiler.com/index.php/topic,187.msg952.html#msg952
I had loads of problems until I tried I2COut / in

Bob

m.kaviani

Quote from: Gamboa on Mar 26, 2021, 05:09 PMBSTART
  BUSOUT $B4
  BUSOUT $00
  'Brestart  (I have tried with restart and without restart )
  BUSOUT $B5
  BUSIN Value
  BSTOP

Hi Gamboa,
I am sure that you considered the I2C pullup resistors.
about your code
1- you sent the writing command $B4
2- sent the address of status register $00
why you write the next BUSOUT $B5? (B5 is reading command)
in the 3rd line, B5 will send to the chip and store in the status_register.
try this:
BSTART
BUSIN READ_COMMAND,ADDRESS,[VALUE]
BSTOP
use this for every read address
Or
BSTART
BUSOUT WRITE_COMMAND,ADDRESS,[VALUE]
BSTOP

keep in mind some addresses just readable or just writable or both of them.
nWAKE pin shall be connect to ground,
as the figure 3 said you must send 2 byte then read the 3rd byte that the device send for micro.

trastikata

QuoteAll I2C transactions must use the 7-bit address 0x5A(I2C _ADDRlow)or 0x5B(I2C _ADDRhigh)when writing to and reading from the CCS811. Table 1shows the register map for CCS811.

Am I missing something or the read address is 5B and not B5?

top204

#4
Please remember, when the Busin or Busout commands are used with multiple parameters, they automatically send Start, Ack and Stop commands.

It is only when the Busin command is used on its own, or the Busout command is used with a single parameter, that they do not send start, Ack or Stop commands. So they can be used seperately. I'll check the compiler manuals and make sure I have outlined this clearly enough.

With slave address', they usually need to be shifted left by 1 position. i.e. Symbol cSlaveAddress  = (DataSheetAddress << 1). Datasheets give the address as if it is a standard 8-bit value, but it actually starts at bit-1 of the address value, and read/write is bit 0. So the address they give will, usually, not work unless it is shifted. I was going to automatically shift the value within the commands, but I did not want to interfere too much with the user's code.