completehasem.blogg.se

Ds1307 codevisionavr
Ds1307 codevisionavr













ds1307 codevisionavr

I was recently finding an attempt to communicate between a master and slave PIC unsuccessful, and I had a DS1307 lying around, so I whipped up some code. You can read in a multibyte burst, sequentially, or a single byte and then send a STOP and start the process over again at a different register location. Looking at you code, I don't see anything glaringly wrong, but if we look at the DS1307 datasheet, page 13, it specifies that to do a data read from a specific location you write the address, the location in the DS1307 registers, then initiate a "Repeated Start" routine, send the address again, then read the data. This line simply is checking any bits that signify that the peripheral is busy, (such as an active start or stop condition, currently clocking out data, etc. The IdleI2C2() function is simply the following: while(I2C2CONbits.SEN || I2C2CONbits.PEN || I2C2CONbits.RSEN || I2C2CONbits.RCEN || I2C2CONbits.ACKEN || I2C2STATbits.TRSTAT)

ds1307 codevisionavr

NotAckI2C2() // Master Aknodledge End of transfer MasterWriteI2C2(0圎1) // Send slave address with read bit MasterWriteI2C2(0圎0) // Send slave address with write bit An example is shown below: StartI2C2() // Send the Start Bit Using the Microchip PLIB legacy libraries for I2C, you need to manually poll for the bus to be idle after each operation.

#DS1307 CODEVISIONAVR CODE#

This code works: rtc_init(0,1,0) // output pin for debugging I worked this RTC with ATMega128 and CodeVisionAVR

  • Adjust the pull-up resistor, try to change to 1.5k/1.8k Ohm.
  • Try to add small delay (10ms) before I2C start and after I2C stop.
  • So when you set second, make sure bit 7 (CH) is 0.ĪND set bit 7 (CH) to zero every time the IC is powering up. I don't know where I am missing the point.īit 7 of Register 0 is the clock halt (CH) bit. So I received 0x00 as the value of n and according to document, 0 means transmission successful. I also used a variable n to check if the values are actually transmitting or not. I am debugging the code and can see all the values in I2C registers are correct but at res = MasterReadI2C2(), nothing shows up in I2C2RCV register which holds the received value and even nothing showing up in the res variable. I am using 163 ((33000000)-2)as BRG value for I2C communication. N = MasterWriteI2C2(0xD0) //device address Updated CODE: OpenI2C2(I2C_EN, 163) // I2C channel Configuration In my code I am using OpenI2C2 to open the i2c channel. I have written the code but don't know why I am not getting data. I am using I2C1 for DS1307 RTC and then using UART2 to send the RTC value to the terminal. I am interfacing DS1307 RTC with PIC32MX795F512L.















    Ds1307 codevisionavr