![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi all, I've used a PIC16f876a and could successfully write 128Byte (as LCD CHR codes) into 24C512 Eeprom, the problem rose when I try to read bytes back and display onto LCD. when doing random read I can successfully read one byte from any where in the memory page, but after the first byte when i send ACK to read more, all i get is 0xff on all byte and LCD shows █. no matter what. ![]() I'd appreciate any help. Farshad | |
| |
| | #2 |
|
Are you sure you're using the right command to read the next byte?
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." | |
| |
| | #3 |
|
Post your code. You must be doing something wrong but I can't think what it might be. Mike. | |
| |
| | #4 |
|
here is my code: as I mentioned the first read is fine but when it goes to the loop for next bytes it's wrong data display on LCD. setup bcf STATUS, RP0 clrf PORTB clrf PORTC bsf STATUS, RP0 ;bank1 movlw b'00011100' movwf TRISC ; PORTC <4:3> as input bcf STATUS, RP0 ;bank0 call INITLCD clrf SSPCON movlw b'00101000' ;init I2C with FOsc movwf SSPCON bcf PIR1, SSPIF ;init XT flag bit bsf STATUS, RP0 ;bank1 clrf SSPCON2 ;init SSPCON2 clrf SSPSTAT bsf SSPSTAT, SMP ;slew disable for 100KHz bcf SSPSTAT, CKE ;SMBus disabled movlw h'9' movwf SSPADD ; 100Khz baud rate bcf STATUS, RP0 ;bank0 movlw d'16' movwf data_count read_mode bsf STATUS, RP0 ;bank1 bsf SSPCON2, SEN ; send Start btfss SSPSTAT, S goto $-1 bcf STATUS, RP0 ;bank0 btfss PIR1, SSPIF ;wait till Start completed goto $-1 bcf PIR1, SSPIF ; clear TXflag bit movlw b'10100000' movwf SSPBUF ;set device address<0>write bsf STATUS, RP0 ;bank1 btfsc SSPSTAT, BF ; check if buffer is empty goto $-1 btfsc SSPCON2, ACKSTAT ; check if ACK received goto $-1 bcf STATUS, RP0 ;bank0 btfss PIR1, SSPIF ;wait till Start completed goto $-1 bcf PIR1, SSPIF ; clear TXflag bit movlw d'0' movwf SSPBUF ; first word address bsf STATUS, RP0 ;bank1 btfsc SSPSTAT, BF ; check if buffer is empty goto $-1 btfsc SSPCON2, ACKSTAT ; check if ACK received goto $-1 bcf STATUS, RP0 ;bank0 btfss PIR1, SSPIF ;wait till Start completed goto $-1 bcf PIR1, SSPIF ; clear TXflag bit movlw d'5' movwf SSPBUF ;second word address page0=0, page1=128 bsf STATUS, RP0 ;bank1 btfsc SSPSTAT, BF ; check if buffer is empty goto $-1 btfsc SSPCON2, ACKSTAT ; check if ACK received goto $-1 bcf STATUS, RP0 ;bank0 btfss PIR1, SSPIF ;wait till Start completed goto $-1 bcf PIR1, SSPIF ; clear TXflag bit bsf STATUS, RP0 ;bank1 bsf SSPCON2, RSEN ;send Restart btfss SSPSTAT, S goto $-1 bcf STATUS, RP0 ;bank0 btfss PIR1, SSPIF ;wait till Start completed goto $-1 bcf PIR1, SSPIF ; clear TXflag bit movlw b'10100001' movwf SSPBUF ;set device address<1>read bsf STATUS, RP0 ;bank1 btfsc SSPSTAT, BF ; check if buffer is empty goto $-1 btfsc SSPCON2, ACKSTAT ; check if ACK received goto $-1 bcf STATUS, RP0 ;bank0 btfss PIR1, SSPIF ; wait XT complete goto $-1 bcf PIR1, SSPIF ; clear TXflag bit data_read bsf STATUS, RP0 ;bank1 bsf SSPCON2, RCEN ;I2C receive enabled btfss SSPSTAT, BF ; check if buffer is full goto $-1 bcf STATUS, RP0 ;bank0 btfss PIR1, SSPIF ;wait till Start completed goto $-1 bcf PIR1, SSPIF ; clear TXflag bit bcf STATUS, RP0 movf SSPBUF, w call LCDWRITE ;data to LCD clrf SSPBUF bsf STATUS, RP0 bcf SSPCON2, ACKDT ;ACK send bsf SSPCON2, ACKEN ;init Sequel ACK bcf STATUS, RP0 ;bank0 btfss PIR1, SSPIF ;wait till Start completed goto $-1 bcf PIR1, SSPIF ; clear TXflag bit decfsz data_count, f goto data_read return read_end bsf STATUS, RP0 ;bank1 bsf SSPCON2, ACKDT ;NO acknowlege bit bsf SSPCON2, ACKEN ;init Sequel ACK bcf STATUS, RP0 ;bank0 btfss PIR1, SSPIF ;wait till Start completed goto $-1 bcf PIR1, SSPIF ; clear TXflag bit bsf SSPCON2, PEN ;send Stop bit btfss SSPSTAT, P goto $-1 bcf STATUS, RP0 ;bank0 btfss PIR1, SSPIF ; wait XT complete goto $-1 bcf PIR1, SSPIF ; clear TXflag bit Last edited by FarshadN; 9th November 2009 at 12:03 PM. | |
| |
| | #5 |
|
Hi please have a look at my code. thanks! | |
| |
| | #6 |
|
Too late for me now. If nobody answers before tomorrow I'll take a look. Mike. | |
| |
| | #7 |
|
Hi Mike! have you had time to look at my code. I also added a "btfsc SSPSTAT, R-W" check after the RCEN was set to slow down the loop, but still same problem all I get is 0xff on all bytes. Last edited by FarshadN; 9th November 2009 at 12:06 PM. | |
| |
|
| Tags |
| byte, eeprom, eeprom read, i2c, pic 16f, read |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Page-mode EEPROM - may I write a singe byte? | atferrari | General Electronics Chat | 2 | 20th June 2009 08:19 AM |
| when pin goes 1, need to send 1 byte to specific telephone number and read it with PC | miro_gt | General Electronics Chat | 2 | 16th April 2009 01:30 AM |
| Atmega EEPROM, does each location = 1-byte? | pwotoole | AVR | 8 | 11th February 2009 08:26 PM |
| How to Read EEPROM without PC | devigan | Electronic Projects Design/Ideas/Reviews | 4 | 19th May 2005 04:02 PM |
| i2c eeprom | jijita | Micro Controllers | 3 | 19th July 2004 07:30 AM |