Jump to content
ELFORUM - Forumul electronistilor

probleme de comunicatie I2c PIC 16F88 - DS1307


Alexxx

Recommended Posts

Am ales cea mai simpla sechema posibila, adica pic-u un lcd 2X20 caractere si un DS 1307. Problema e urmatoarea, pot sa configurez bitii ceasului dar nu ii citeste. Am activat SQW/OUT si am masurat frecventa, intradevar am frecventa pe care o setez, in schimb nu pot sa citesc nimic din el. Foloesc HT-PIC. Atasez si cod-ul. Va rog daca puteti sa ma ajutati. Multumesc!#include #include #include #include "intrp.h"#include "lcd_mb.h"#include "delay.h"#include "i2c.h" __CONFIG(WDTEN & HS & LVPDIS & PWRTDIS & BORDIS);char s[20];int n=0;int k=0;#define ceas 0xD0#define blink RA2 main(){ asm("clrwdt"); OPTION=0b11001111;INTCON=0b11100000;PIE1=0b01111100;PIR1=0;PIE2=0;PIR2=0;ANSEL=0;CMCON=0x07;TRISA=0b00000000;PORTA=0;TRISB=0b00000000;PORTB=0; TMR0IE=1;ei();asm("clrwdt"); i2c_WriteTo(ceas);i2c_PutByte(0x00);i2c_PutByte(0b00000001);i2c_WriteTo(ceas);i2c_PutByte(0x01);i2c_PutByte(0b00000001);i2c_WriteTo(ceas);i2c_PutByte(0x02);i2c_PutByte(0b00000001);i2c_WriteTo(ceas);i2c_PutByte(0x07);i2c_PutByte(0b00010001); asm("clrwdt"); initLCD(); asm("clrwdt"); clrLCD; line1(); strcpy(s," "); print(s); line2(); strcpy(s," COMUNICARE I2C "); print(s); asm("clrwdt"); while(1){ asm("clrwdt"); if(cks>50){ blink=!blink; i2c_WriteTo(ceas); i2c_PutByte(0x00); i2c_ReadFrom(ceas); k=i2c_GetByte(I2C_LAST); sprintf(s,"%d",k); gotoxy(2,1); print(s); n++; sprintf(s,"%d",n); gotoxy(1,17); print(s); cks=0; } }}

Link to comment
Share on other sites

  • 4 weeks later...

Probabil ca ai rezolvat problema intre timp...Cu ani in urma cand am legat si eu primul DS1307 de un Pic m-am lovit de o problema similara. Puteam sa scriu in el dar nu citeam decat 00 sau FF ( nu imi mai aduc aminte exact ). Problema in cazul meu era ca pointerul de adresa se afla intr-o zona aiurea, in portiunea de SRAM a alui DS1307. Setarea pointerului se face numai in modul de scriere, la citire incrementarea facandu-se automat la adresa urmatoare dupa fiecare ack. Solutia gasita de mine atunci a fost sa fac intai o scriere la adresa 3F ( ultima locatie SRAM ) si apoi citirea la rand a datelor. Programelul facut in jal arata cam asa:-- scrie 0 la adresa 3F ( ultima locatie SRAM a DS1307 )2c_put_start i2c_put_data ( 0xD0 )i2c_wait_acki2c_put_data ( 0x3F )i2c_wait_acki2c_put_data ( 0x00 )i2c_wait_acki2c_put_stopi2c_put_starti2c_put_data ( 0xD1 )i2c_wait_acki2c_get_data ( sec )i2c_put_acki2c_get_data ( min )i2c_put_acki2c_get_data ( ore )i2c_put_acki2c_get_data ( nr_zi )i2c_put_acki2c_get_data ( zi )i2c_put_acki2c_get_data ( luna )i2c_put_acki2c_get_data ( an )i2c_put_nack_stopSper sa iti fie de folos

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...
  • 5 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines