element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum SI1145 sensor address register read problems
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 1 reply
  • Subscribers 300 subscribers
  • Views 494 views
  • Users 0 members are here
  • i2c
  • SI1145
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

SI1145 sensor address register read problems

hazard
hazard over 2 years ago

Hello

if anyone can help me with a SI1145 sensor.


I' trying usee this sensor with pic24fj, but no good result from the registers.

I'm just try read the PART_ID from the sensor, but I can't read the register at first time. i.e I call a function SI1145_Read_byte(uint8_t regaddress), some thing like this (I will post the code)

but for read the correct value I need call this function two time. at the second call return me a correct value from registe.


example:


If read the register 0x02 (SEQ_ID) I expect read 8dec.

but at first read  a NULL value.

maybe with some picture I can explain beter.

image

image

image

I2C.c

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <stdbool.h>
#include "I2C1.h"
#include "TIMERS.h"


void I2C1_ACK_SEND(void)
{
    I2C1CONLbits.ACKDT=0;//config to send ACK
    while(I2C1CONLbits.ACKEN==1){};
}

uint8_t I2C1_ReadData(void)
{
    I2C1CONLbits.RCEN = 1;
    uint8_t data=I2C1RCV;
    while(I2C1STATbits.RBF==0){};
    I2C1_IDLE();//while(I2C2STATbits.TRSTAT==1){};
    return data;
}

void I2C1_ReStartCondition()
{
    I2C1CONLbits.RSEN=1;
    I2C1_IDLE();//while(I2C2CONLbits.RSEN==1){};   
}

void I2C1_Send_ACK(void)
{
    I2C1CONLbits.ACKDT=0;//config to send ACK
    while(I2C1CONLbits.ACKEN==1){};
}

void I2C1_ACK_READ(void)
{
    while(I2C1STATbits.ACKSTAT==1){};
}

void I2C1_Send_NACK(void)
{
    I2C1CONLbits.ACKDT=1;//config to send NACK
    while(I2C1CONLbits.ACKEN==1){};
}

void I2C1_Sendaddress(uint8_t dataaddress)
{
    I2C1TRN = dataaddress<<1;
    I2C1_IDLE();//while(I2C2STATbits.TRSTAT==1){};
}

void I2C1_SendByte(uint8_t data)
{
    I2C1TRN = data;
    I2C1_IDLE();//while(I2C2STATbits.TRSTAT==1){};
}

void I2C1_StopCondition(void)
{
    I2C1CONLbits.PEN=1;
    I2C1_IDLE();//while(I2C2CONLbits.PEN==1){};
}

void I2C1_StartCondition(void)
{    
    I2C1CON1bits.SEN=1;
    I2C1_IDLE();//while(I2C2CONLbits.SEN==1){};
}

void I2C1_IDLE(void)
{
    while(I2C1CONLbits.RCEN==1 || I2C1CONLbits.PEN==1 || I2C1CONLbits.RSEN==1 ||
          I2C1CON1bits.SEN==1 || I2C1STATbits.TRSTAT==1){};//IDLE
          
}

void Init_I2C1(void)
{
    I2C1BRG = 9;
    
    I2C1CONLbits.I2CSIDL=0;//Continues module operation in Idle mode
    I2C1CONLbits.A10M=0;//I2CADD is a 7-bit slave address
    I2C1CONLbits.DISSLW=1;//1=Slew rate control is disabled for Standard Speed mode (100 kHz, also disabled for 1 MHz mode) || 0=Slew rate control is enabled for High-Speed mode (400 kHz)
    I2C1CONLbits.I2CEN=1;//Enables the I2C2 module, and configures the SDA2 and SCL2 pins as serial port pins
}

SI1145.c

uint8_t  SI1145_Burst_Read_Data_UI8(uint8_t add_register_UI8)//uint8_t add_register_UI8, uint8_t dim)//return 8bits data from I2C Register
{
    //Host Interface Burst Read sequence
    I2C1_StartCondition();
    I2C1_SendByte(0xC0);
    I2C1_ACK_READ();
    I2C1_SendByte(add_register_UI8);
    I2C1_ACK_READ();
    I2C1_ReStartCondition();
    I2C1_SendByte(0xC1);
    res = I2C1_ReadData();
    I2C1_Send_NACK();
    I2C1_StopCondition(); 

    
    return res;  
}

more prints with only one call

image

image

image

register address

image

register value

image

  • Sign in to reply
  • Cancel
  • shabaz
    0 shabaz over 2 years ago

    I don't know the answer, but (until hopefully someone else can chime in with better information) - if it were me, I'd be looking for further patterns, to get to the bottom of this. It wasn't clear, does every second operation work, or does every operation work apart from just the first one?

    Also, are you sure the debugger updates the memory view for sure? It could be an IDE issue too. I have not used PIC devices for ages, and not used Pickit, so I don't know their behaviour. You could eliminate this by (say) turning on an LED if the expected value is read.

    Probably, the code needs to be set up to run for (say) 1000 times, and for it to count the errors itself (by comparing with the expected value), and display them. Anything less than 100.0% pass rate is of course an issue.

    A scope may be needed to view things (and to confirm the I2C bus lines are initially in the correct state, and that the voltage levels are as expected and not marginal, and that the I2C timings meet the sensor needs (it has a specific range for I2C but speed, which should be fine, but it's worth double-checking with a 'scope).

    Also wiring, circuit etc matters, it could be making things marginal; a photo of the setup would be good too.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube