Jump to content
ELFORUM - Forumul electronistilor

I2C cu ST MICROELECTRONICS M24256-BW si 18F4550, C18


Recommended Posts

n-am mai lucrat cu I2C pana acum. daca nu voi rezolva problema, foarte probabil ca nici nu o sa lucrez vreodata...

partea hard:

ST MICROELECTRONICS M24256-BWMW6G este cuplata : E0, E1, E2 la gnd. !WC la gnd. SDA la RB0/SDA, cu un pull-up de 4k7. SCL la RB1/SCL.

crystalul este de 20MHz

partea soft:

#pragma config WDT=OFF#pragma config PBADEN=OFF#pragma config PWRT = OFF#pragma config PLLDIV = 5		//20MHz#pragma config FOSC = HSPLL_HS   //20 MHz#pragma config CPUDIV = OSC1_PLL2  //20 MHz#pragma config MCLRE = ON#pragma config LVP = OFF#pragma config USBDIV = 2#pragma config VREGEN = ON
/apoi, in initializarea sistemului

 

unsigned char resp;//init TMR3T3CON=0x80;//0xA0;IPR2bits.TMR3IP=1;PIE2bits.TMR3IE=1;T3CONbits.TMR3ON=1;INTCON=0xC0;ADCON1=0x0f;//intreg PORTA este digitalCMCON=0x07;...TRISB=0x03; //RB1:0 intrari, pr memoria seriala...OpenI2C(MASTER,SLEW_ON);SSPADD=0x77;...resp=EEByteWrite_INT_Addr(0xA0, 0x0001, 0xA5);EEAckPolling(0xA0);scens_count=EERandomRead(0xA0,0x01);
toate bune si frumoase, resp ramane 0xff, iar scens_count la fel, probabil din spirit de solidaritate.

Am rescris unsigned char EEByteWrite_INT_Addr(unsigned char, unsigned int, unsigned char);

if ( !SSPCON2bits.ACKSTAT )   // test for ACK condition received    {       if ( WriteI2C((unsigned char) (address >>8) ) )  // write word address for EEPROM      {	    StopI2C();         return ( -3 );            // set error for write collision      }      if ( WriteI2C((unsigned char) (address & 0x00ff) ) )  // write word address for EEPROM      {	    StopI2C();         return ( -3 );            // set error for write collision      }...
pornind de la vechea unsigned char EEByteWrite(unsigned char, unsigned char, unsigned char);

tinand cont ca functia returneaza -1 in caz de Bus Collision error dar tipul returnat este unsigned char, poate fi asta? daca da, cum trebuie sa fac? daca nu...

cam asta ar fi. are cineva rabdarea sa ma indrume cum sa ies din impas?

multumesc.

Link to comment
  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

ST MICROELECTRONICS M24256-BWMW6G este cuplata : E0, E1, E2 la gnd. !WC la gnd.

 

Eu as lega !WC la un pin al picului; din cate am vazut eu in data sheet, WC asta stabileste modul de adresare al memoriei (scriere - WC==0, citire WC ==1)

 

SDA la RB0/SDA, cu un pull-up de 4k7. SCL la RB1/SCL.

Eu as mai pune si la SCL o rezistenta pull-up (sau as activa weak pull-up pentru portul b).

 

La soft nu ma pricep (nu stiu exact ce compilator e (c18?) si nici functiile nu-mi spun nimic), da' mi-a sarit in ochi

 

...TRISB=0x03; //RB1:0 intrari, pr memoria seriala

 

Dupa parerea mea, SCL e iesire si trebuie configurat ca atare; tu l-ai facut intrare si s-ar putea ca problema ta sa fie de la lipsa clock-ului - pagina 209 din Data sheet

 

Note 1: When enabled, the SDA and SCL pins must be properly configured as input or output.
Link to comment

Dupa parerea mea, SCL e iesire si trebuie configurat ca atare; tu l-ai facut intrare si s-ar putea ca problema ta sa fie de la lipsa clock-ului - pagina 209 din Data sheet

 

Two pins are used for data transfer:

• Serial clock (SCL) – RB1/AN10/INT1/SCK/SCL

• Serial data (SDA) – RB0/AN12/INT0/FLT0/SDI/SDA

The user must configure these pins as inputs by setting

the associated TRIS bits.

asta-i din datasheet-ul 4550, exact de la I2C, asa ca TRISB pare ok...

compilatorul pe care-l folosesc este C18, v3.35.

am rescris ceva functii... pentru a putea adresa o plaja mai mare de 255 locatii, cat permiteau vechile functii (unsigned char l-am portat catre unsigned int). de fapt, pentru a adresa orice, ca memoria asta asteapta mai intai upper byte si apoi lower byte din adresa.

...

intre timp (din momentul in care am inceput sa scriu postul si pana acum), tot sapand, am dat de hiba: am lasat WC in aer si a mers:

"When unconnected,

the signal is internally read as VIL, and

Write operations are allowed." (din datasheet)

bineinteles am facut pull up si la SCL, cu un 4k7 (fara nu prea merge).

ca urmare, liviule, o mie de multumiri! :101

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • 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