Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

usart interrupts help...

Status
Not open for further replies.

piscaroy

Junior Member level 3
Joined
Aug 12, 2004
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
531
hi, hmmm in my project i need to get data from serial com port and store in eeprom..and im thinking what if 1st data is in progress of storing but another data is send through the serial port will the data be recieve? and i do a trail using the PC to send thru to the pic..while runing 1st data i click send 2nd data and my target board hanged...im wondering whether usart interrupts will help or polling(but im not very sure about these 2 functions)...or any1 have any sample codes of usart interrupts in C language for pic18f452 (c18 compiler preferably, but if not ASM or other C also can) just to let me have a reference...? pls help thankz

best regards..
 

Hi,

The best place to get some example of serial management and EEPROM management is Microchip's site. They have a full shelf of applications notes on this subject :

h**p://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2048

* = t
 

I have get the same question several months ago. I must receive GPS module's data in USART0 every second. And it's baud rate is 4800bps.But I finish receive 1st data. I have to send it to another usart port. When I send it ,the 2st data send form the GPS module.So I will miss the 2nd data.But I hope can solution the question. Don't miss any data . So I
use two MPU. They are named MPU1 and MPU2.When the MPU1 receive the GPS module's data via usart at 4800bps. The MPU2 use 8-lines data bus and 3-lines control bus get the data form MPU1 fastly.So the MPU1 only receive data , and the MPU2 only send data. ^^
 

Maybe you're flooding the Rx buffer, due to the EEPROM accesses are slower than UART rate, so you should code a FIFO-buffer to temporarily storage the received data.
Regards
 

:p
It,s easy!
You read data from USART and save it in RAM buffer (increase writing index and compare it with length of buffer, if excess should reset writing index). After Escape from Interrupt Service Rountine (ISR), you write into EEPROM data which is readed from RAM buffer, and increase index read, compare it with length of buffer and reset it if full.
Two process is nearly the same time.
In ISR,Write RAM buffer is only writing index equal to reading index. If vice versa, it is full buffer and depend your soft.
In main program, if writing index is not the same reading index -> have (a) new data which is need to write EEPROM. After writing finish, remember increase reading index.
 

conkhicon said:
... After writing finish, remember increase reading index.

Additionally, you should disable the UART interrupt before writing data, and re-enable it after increasing the reading index, in order to avoid data-sharing issues.
 

PIC18F452 specification write data to EEPROM used
4ms for write cycle .
If you use C langauge I think you should
use write cycle time =5ms.
So you can write stream data 200 byte/Second
# Design a good hand shake for programing.
 

Regnum said:
conkhicon said:
... After writing finish, remember increase reading index.

Additionally, you should disable the UART interrupt before writing data, and re-enable it after increasing the reading index, in order to avoid data-sharing issues.

Not require. Disable UART Int when only write instruction. Most time is waiting flag signalling to finish and so that re-enable UART int iinstantaneously after last write and before into block waiting flag. This is not loss data from UART.
Ex code for PIC 18F8720:

EEhighlow.two = addr;
EEADRH = EEhighlow.one[1];
EEADR = EEhighlow.one[0];
EEDATA = Value;
EECON1bits.EEPGD = 0; // Acess EEROM
EECON1bits.CFGS = 0; // Acess Flash&EEROM
EECON1bits.WREN = 1; // Write Enable
INTCONbits.GIE = 0; // Disable Interrupt
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
INTCONbits.GIE = 1; // Enable Interrupt

while(PIR2bits.EEIF==0) { // Not Write finish ->waiting
....more instructions;
}
PIR2bits.EEIF=0; // Clear flag
EECON1bits.WREN = 0; // Write Disable
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top