PDA

View Full Version : I2C Communication between PIC18F4550 and AS5600



soren7
- 12th March 2024, 17:14
Hello,
I am trying to communicate between PIC and AS5600 chip. I am not sure if the commands I send are correct. The only data I receive back from AS5600 is "6" for B0 and "6" for B1.

Here is part of my code:

define LOADER_USED 1
define OSC 24
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 38400
DEFINE HSER_CLROERR 1
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTD
Define LCD_RSBIT 1
Define LCD_EREG PORTD
Define LCD_EBIT 0
define LCD_BITS 4
define LCD_LINES 2
define CCP2_REG PORTC
define CCP2_BIT 1
ADCON1 = 15 'make all inputs and outputs digital


TRISA = %11111111 'set up port A as input
TRISC = %10000000 'set up port C as output/input (Rx-1,Tx-0)
TRISB = %11111111 'set up port B as input
TRISD = %00000000 'set up port D as output
TRISE = %00000000 'set up port E as output


PORTC = %01000100
DEFINE I2C_SCL PORTB,1
DEFINE I2C_SDA PORTB,0
DEFINE I2C_SLOW 1
DEFINE I2C_HOLD 1
DEFINE CHAR_PACING 102

start:
B0 = 0
B1 = 0
pause 100
i2cwrite PORTB.0,PORTB.1,$36,$0E,[0]
pause 10
i2cwrite PORTB.0,PORTB.1,$36,$0E,[1]
pause 10
I2CREAD PORTB.0,PORTB.1,$36,$0E,
pause 10
I2Cwrite PORTB.0,PORTB.1,$36,$0F,[0]
pause 10
I2Cwrite PORTB.0,PORTB.1,$36,$0F,[1]
pause 10
I2CREAD PORTB.0,PORTB.1,$36,$0F,[B1]
pause 10
LCDOut $FE, 1, dec B1
LCDOut $FE, $C0, dec B0
[B]goto start

Any help you can provide in this matter will be appreciated.

Ioannis
- 12th March 2024, 20:11
Well, from the datasheet I could not understand much about how to read data from the chip.

What are the $0F and $0E after $36 in your commands?

Also, are you sure you have connected correctly data and clock of the I2C bus from PIC to AS5600?

Ioannis

richard
- 12th March 2024, 22:21
the data sheet address is a 7 bit address pbp uses 8 bit address
what are ic2writes for ?
they seem to be of no value that i can see
you defined sda and scl why not use them ?

more like

start:
I2CREAD SDA,SCL,$6C,$0E,[B0,B1]
LCDOut $FE, 1, dec B1
LCDOut $FE, $C0, dec B0
goto start

soren7
- 13th March 2024, 10:47
$36 is I2C address for AS5600
$0F and $0E address for low and high bytes from encoder.
I am pretty sure the data and clock are connected correctly. Also I pull them hight with 4.7k resistor.

soren7
- 13th March 2024, 10:54
what are ic2writes for ?
I thought that I need to send trigger first to AS5600 (Master mode), but I might be wrong.

Can I ask you why did you use $6C in read command? Shouldn't it be $36?

richard
- 13th March 2024, 11:18
$36 is I2C address for AS5600

the data sheet address $36 is a 7 bit address pbp uses an 8 bit address scheme



I thought that I need to send trigger first to AS5600 (Master mode), but I might be wrong.

You may well have to "configure" the device but for an i2c read transaction that is an unnecessary step


$0F and $0E address for low and high bytes from encoder.
both registers can be read in a single transaction as i indicated

soren7
- 13th March 2024, 11:43
the data sheet address $36 is a 7 bit address pbp uses an 8 bit address scheme

Does it mean that I can not communicate or I need to adjust the address?


You may well have to "configure" the device but for an i2c read transaction that is an unnecessary step

ok


both registers can be read in a single transaction as i indicated

ok


Thank you.

soren7
- 13th March 2024, 14:20
I have used this one:
I2CREAD SDA,SCL,$6C,$0E,[B0,B1]
and it works. Thank you very much for your help