The program in #54 is for the simulator.If you have an oscilloscope then use it. It gives better information than an LED at high frequencies.
Write a main loop to toggle an LED without using delay.
Show your code and report back.
The program in #54 is for the simulator.If you have an oscilloscope then use it. It gives better information than an LED at high frequencies.
Write a main loop to toggle an LED without using delay.
Show your code and report back.
Hi Mr C,If you have an oscilloscope then use it. It gives better information than an LED at high frequencies.
Write a main loop to toggle an LED without using delay.
Show your code and report back.
Hi J,Receiver is not enabled.
It gets now the interrupt from other source, probably TX interrupt.
You should setup the receiver, look #54
Setup the interrupts only for the receiver.
'**** Oshonsoft Basic Simulation for USART Rx with interrupts
'PIC8LF4620 8MHz
Define SIMULATION_WAITMS_VALUE = 1
Define CLOCK_FREQUENCY = 8
'*** Setup interrupts ***
RCON.IPEN = 1 'IPEN: Int Priority Enable bit 'This MUST be included when using Interrupts (Priority HIGH/LOW)[#189 hserin blocking]
PIE1 = %00100000 'RCIE: EUSART Receive Interrupt Enable bit [ 1=en ]
INTCON.PEIE = 1 'PEIE/GIEL: Peripheral Interrupt Enable bit
INTCON.GIE = 1 'GIE/GIEH: Global Interrupt Enable bit *** s
' **** Setup Hw USART ****
Hseropen 9600
Dim char As Byte
Dim str1(20) As Byte ' *** received message comes to str1
Dim rxi As Byte ïndex to Str1
Dim msg_rdy As Bit
rxi = 0
msg_rdy = 0
Enable High
Main:
Break '***stop and put a short msg ending with "!" in to Simulator Rx window
While not msg_rdy // **** the real program can run here and check msg_rdy as needed
Wend
Break '**** stop, now the Str1 can be looked at the variable window
End
On High Interrupt
Save System
If PIR1.RCIF = 1 Then
char = RCREG
str1(rxi) = char
rxi = rxi + 1
Endif
If char = "!" Then ' *** ends the message ****
msg_rdy = 1
Endif
Resume
Hi J,This is a barebones Oshonsoft simulator demo to receive a message by interrupts.
No checking of errors, overflows, message start characters etc.
You have to do the hard work.
Code:'**** Oshonsoft Basic Simulation for USART Rx with interrupts 'PIC8LF4620 8MHz Define SIMULATION_WAITMS_VALUE = 1 Define CLOCK_FREQUENCY = 8 '*** Setup interrupts *** RCON.IPEN = 1 'IPEN: Int Priority Enable bit 'This MUST be included when using Interrupts (Priority HIGH/LOW)[#189 hserin blocking] PIE1 = %00100000 'RCIE: EUSART Receive Interrupt Enable bit [ 1=en ] INTCON.PEIE = 1 'PEIE/GIEL: Peripheral Interrupt Enable bit INTCON.GIE = 1 'GIE/GIEH: Global Interrupt Enable bit *** s ' **** Setup Hw USART **** Hseropen 9600 Dim char As Byte Dim str1(20) As Byte ' *** received message comes to str1 Dim rxi As Byte ïndex to Str1 Dim msg_rdy As Bit rxi = 0 msg_rdy = 0 Enable High Main: Break '***stop and put a short msg ending with "!" in to Simulator Rx window While not msg_rdy // **** the real program can run here and check msg_rdy as needed Wend Break '**** stop, now the Str1 can be looked at the variable window End On High Interrupt Save System If PIR1.RCIF = 1 Then char = RCREG str1(rxi) = char rxi = rxi + 1 Endif If char = "!" Then ' *** ends the message **** msg_rdy = 1 Endif Resume
Hi E,
I think Hseropen 9600 takes care of it. It is command for HW UsartHi J,
And I was looking forward to doing this myself
Thanks very much, I'll put the Aspirin away, much appreciated.
Regarding the 8BIT 16 BIT choice: [ RCSTA.RX9 = 0 '0 = Selects 8-bit reception ] and This routine uses 8BIT, but later there are H and L BYTES, should this be set for 8 or 16BIT?
Regarding the BAUD rate: How do I select [ BAUDCON.BRG16 = 1 '1 = 16-bit Baud Rate Generator – SPBRGH and SPBRG ] ?
Thanks, C.
Hi J,I think Hseropen 9600 takes care of it. It is command for HW Usart
Can't you just send 16bit as two 8bit bytes, when you know where they are in the message?Hi E,
My question was more to do with setting up UART or PIC.
The UART uses 8BIT, but the MAIN LOOP uses Two's compliment H and L.
As I'm setting up the UART, I assme that I should set that setting to 8BIT, but for the SPI H an L BYTEs they will need 16BIT.
Thanks, C.
Hi J,Can't you just send 16bit as two 8bit bytes, when you know where they are in the message?
Hi E,hi,
'While msg_rdy = 0 'the real program can run here and check msg_rdy as needed
When is msg_rdy NOT = 0. ?
E
In the ISR when at the end of the message set msg_rdy = 1Hi E,
This is a temporary LOOP, that is broken by the INTERRUPT, and will not be there once the MAIN program comes back.
I haven't checked the actual timing, but just watching the SIM, I'm surprised by the time the processor has to go back to the MAIN LOOP in between $ Sentence digits, coming in.
If you're testing with the SIM, here are some sentences:
$GPRMC,123519,A,4807.038,N,01131.000,W,022.4,084.4,230394,003.1,W*6A?
$GPRMC,123519,A,4807.038,N,01131.000,W,W*6A? 'C' = HEX 0X43 DEC 67
$QEIDEG,123,W 'D' = HEX 0X47 DEC 71
$REMOTE,12,20,50,W [remvolt,remalt,remdist],? 'R' = HEX 0X52 DEC 82
C
The simulator is really slow when receiving characters.Hi E,
This is a temporary LOOP, that is broken by the INTERRUPT, and will not be there once the MAIN program comes back.
I haven't checked the actual timing, but just watching the SIM, I'm surprised by the time the processor has to go back to the MAIN LOOP in between $ Sentence digits, coming in.
If you're testing with the SIM, here are some sentences:
$GPRMC,123519,A,4807.038,N,01131.000,W,022.4,084.4,230394,003.1,W*6A?
$GPRMC,123519,A,4807.038,N,01131.000,W,W*6A? 'C' = HEX 0X43 DEC 67
$QEIDEG,123,W 'D' = HEX 0X47 DEC 71
$REMOTE,12,20,50,W [remvolt,remalt,remdist],? 'R' = HEX 0X52 DEC 82
C
Hi J,The simulator is really slow when receiving characters.
A message ~5 charactes took tens of seconds in the original demo.
Real time execution of the ISR is about 40us at 8MHz.
The ISR slows the processor less than 4% at 8MHz. How critical it is to detect fast the end of the message ?Hi J,
The simulator is really slow when receiving characters.
I know, from the hours, I've sat watching it
A message ~5 charactes took tens of seconds in the original demo.
Real time execution of the ISR is about 40us at 8MHz.
I'm not used to these speeds, so take some comprehending, but my thought was that there appears to be some time in between the $Sentence digits, for the processor to work on the MAIN LOOP, until the next digit.
C
by Jeff Child
by Jake Hertz
by Duane Benson
by Duane Benson