PDA

View Full Version : I2CRead and USART interrupt



HenrikBuhl
- 8th January 2007, 13:29
Hello Ladies and Gentlemen,

I am working on a project that is starting to get me somewhat frustrated...

The thing is.. I have a 18F6720 with a 4x20 LCD, USART comms, and a 24LC256 EEPROM connected.

For the LCD I use the PBP LCDOUT routines as well as for the EEPROM.
For the USART reception and the LCD backlight I use an asm interrupt routine.

In the E2PROM I have stored predefined text strings for the LCD.
When the user has not been presseing buttons for at while, the system returns to an "idle" state where the backlight is turned down to about 1/3.

the code part that causes me headache is this:
for n=0 to 19

temp1=n+(rec*20)+temp
I2CREAD SDA,SCL,160,temp1,[text[n]]
text[n]=text[n]-48

next n

temp1 is temporary adress for EEPROM,
rec is the record in the EERPOM I wish to acces
text[20] is my working array for the current record (AD values etc. may be added before written to the LCD)

It seems that when a USART interrupt occurs during the I2CREAD statement it might be reversed to a write - causing random characters to be written to the EEPROM. Usually it is characters 161 and 255 just by each other.
The characters makes no sense together with the communication.

The fast one might suggest simply disabling interrupts during the I2Cread - but this leads to poor communications and flickering backligt..

I hope my description makes sense - Is there anyone outthere who can give me a clue of where to look.

Very best regards
HenrikBuhl

Dave
- 8th January 2007, 13:53
HenrikBuhl, What is the baudrate you are using? You are only acquiring 1 byte from your eeprom. I to use a 18F6720 with 2 24LC1025's, 2 active ASM driven comms @ 38.4k baud and I read 128 bytes or a page when I turn off all interrupts momentarily. The usart has a 2 byte buffer so if your baudrate is relatively low you should not loose any characters in your comm's. By the way you mention that your LCD dimming flickers. I to have an LCD on my product but I use the CCP1 & CCP2 PWM module's for the contrast as well as the backlight dimming. That way there is a continuous pwm signal to the circuitry + you have 1024 steps of backlighting.

Dave Purola,
N8NTA

HenrikBuhl
- 10th January 2007, 06:36
Hi Dave,

thanks for your reply.

My comms are running at 19,2Kbaud, and actually I am reading 20 bytes from my EEPROM in a For-Next loop.
This 20-byte-reading is done 4 times just after each other in order to get all 4 lines for the display.
Unfortunately, I can't use the CCP function for the LCD as they are used for Analog Outputs.

But! I had a breakthrough just a few minutes after submitting the original post.
Instead of reading the 20bytes in a For-Loop - reading it as a string seems to solve the problem - even without disabling interrupts.
The data are garbled anyway, but I can avoid making readouts to the display during communications.

HenrikBuhl

Dave
- 10th January 2007, 13:04
HenrikBuhl, That is the way I read the EEPROM, with the string modifier. My array is 128 bytes in size so it is easy to do page writes and string reads.

Dave Purola,
N8NTA