I2C Communication between PIC18F4550 and AS5600


+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2024
    Posts
    5

    Default I2C Communication between PIC18F4550 and AS5600

    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,[B0]
    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
    goto start

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

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: I2C Communication between PIC18F4550 and AS5600

    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

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: I2C Communication between PIC18F4550 and AS5600

    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
    Warning I'm not a teacher

  4. #4
    Join Date
    Mar 2024
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: I2C Communication between PIC18F4550 and AS5600

    $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.

  5. #5
    Join Date
    Mar 2024
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: I2C Communication between PIC18F4550 and AS5600

    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?


  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: I2C Communication between PIC18F4550 and AS5600

    $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
    Warning I'm not a teacher

  7. #7
    Join Date
    Mar 2024
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: I2C Communication between PIC18F4550 and AS5600

    Quote Originally Posted by richard View Post
    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.

  8. #8
    Join Date
    Mar 2024
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: I2C Communication between PIC18F4550 and AS5600

    I have used this one:
    I2CREAD SDA,SCL,$6C,$0E,[B0,B1]
    and it works. Thank you very much for your help

Similar Threads

  1. Replies: 18
    Last Post: - 4th July 2017, 14:26
  2. PIC18F I2C Communication with Arduino
    By picmilan in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 14th July 2016, 21:38
  3. Replies: 0
    Last Post: - 26th May 2012, 13:57
  4. EEprom and MCP9801 I2C communication problems
    By aajgss in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 3rd September 2011, 21:45
  5. Replies: 2
    Last Post: - 10th June 2005, 02:34

Members who have read this thread : 8

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts