Author Topic: Need help figuring out a PIC I2C function  (Read 240 times)

0 Members and 1 Guest are viewing this topic.

Offline Ground_Loop

  • Contributor
  • Posts: 5
  • Country: us
Need help figuring out a PIC I2C function
« on: October 21, 2019, 10:03:02 am »
Within the I2C simple appliance there is a function to write a byte out to a target device as shown below.  What I'm having trouble with is the meaning of the second parameter "register." Does this refer to a register in the PIC or the target device and if in the PIC why a register followed by a "data" parameter.  I am trying to write data to a display and to my knowledge it does not require an register parameter for data sent.  If register refers to the Slave device can a dummy argument be inserted?

i2c_write1ByteRegister(i2c_address_t address, uint8_t reg, uint8_t data)
Parameters:
address:  Type: i2c_address_t;  The slave address
reg:  Type: uint8_t;  The register address to be written
data:  Type: uint8_t;  The data to be written
« Last Edit: October 21, 2019, 10:20:23 am by Ground_Loop »
 

Online CJay

  • Super Contributor
  • ***
  • Posts: 3355
  • Country: gb
  • M0UAW
Re: Need help figuring out a PIC I2C function
« Reply #1 on: October 21, 2019, 10:11:55 am »
It refers to the slave address, every I2C device has an address and if you fail to provide it then the device will completely ignore your write because it will assume it's meant for some other device on the bus.
M0UAW
 

Offline Ground_Loop

  • Contributor
  • Posts: 5
  • Country: us
Re: Need help figuring out a PIC I2C function
« Reply #2 on: October 21, 2019, 10:19:09 am »
Oops, my mistake. I was referring to the register parameter.  I get the address part, just not the register parameter.  Original post edited.
« Last Edit: October 21, 2019, 10:20:52 am by Ground_Loop »
 

Offline ggchab

  • Regular Contributor
  • *
  • Posts: 204
  • Country: be
Re: Need help figuring out a PIC I2C function
« Reply #3 on: October 21, 2019, 11:29:38 am »
It depends on the library and the slave. "reg" may refer to a location on the slave were "data" has to be written. "reg" and "data" may simply be sent one after the other on the I2C bus !
 

Offline kamtar

  • Contributor
  • Posts: 25
Re: Need help figuring out a PIC I2C function
« Reply #4 on: October 21, 2019, 02:49:52 pm »
a register is register/memory address in your slave device and data is what gets written there.
 

Offline Ground_Loop

  • Contributor
  • Posts: 5
  • Country: us
Re: Need help figuring out a PIC I2C function
« Reply #5 on: October 21, 2019, 04:54:47 pm »
a register is register/memory address in your slave device and data is what gets written there.

So what happens to the register address data when the slave device does not expect it? Is it treated as just another data byte?  I'm sending data to a LCD display with I2C adaptor.  I've done this with Teensy controllers and don't see that I ever needed a register parameter.  I suppose I could use  'i2c_writeNBytes(i2c_address_t address, void* data, size_t len)' and just set len=1.
 

Offline ggchab

  • Regular Contributor
  • *
  • Posts: 204
  • Country: be
Re: Need help figuring out a PIC I2C function
« Reply #6 on: October 21, 2019, 07:30:58 pm »
'i2c_writeNBytes(i2c_address_t address, void* data, size_t len)' is probably a better function in your case.
And if you write to an LCD, I guess you'll have to send more than one byte !
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf