Do I understand hserstup on 28X2?

MartinM57

Moderator
While waiting for my 28X2's to arrive:

If I use e.g. HSERSETUP B9600_8, %00000111 then:

- I can just use the standard download circuit on the hserin/hserout pins and communicate to a PC via a standard serial programming cable?

- If I'm using ADC and having one PC connected to hserin/hserout (for control of the app)and another connected to Serial In/ Serial Out (for re-programming) then I should use the enhanced download circuit on the Serial In/Serial Out pin pair and on the hserin/hserout pin pair?

- I get an hserflag interrupt on the very first incoming character to the hserin pin, but I don't have to do anything with it - bytes will continue to collect in the scratch pad in the background?

- Can I read the hserflag outside of an interrupt routine and do my own thing when I want to?

- ...and no doubt a few other questions that will spin off from these!

Ta
Martin
 

tiscando

Senior Member
While waiting for my 28X2's to arrive:

If I use e.g. HSERSETUP B9600_8, %00000111 then:

- I can just use the standard download circuit on the hserin/hserout pins and communicate to a PC via a standard serial programming cable?

- If I'm using ADC and having one PC connected to hserin/hserout (for control of the app)and another connected to Serial In/ Serial Out (for re-programming) then I should use the enhanced download circuit on the Serial In/Serial Out pin pair and on the hserin/hserout pin pair?
Looks like you actually can because I've just found out that you can, on X2 parts, invert the Rx (hserin) signal with bit2 high.:) Also, the huge pic18f2520 manual states in the general I/O port section that all I/O pins have protection diodes, but I think it's best results to use a schottky bat85 diode as in the enhanced download circuit if you are using a "D" port serial download cable.

- I get an hserflag interrupt on the very first incoming character to the hserin pin, but I don't have to do anything with it - bytes will continue to collect in the scratch pad in the background?
Every time after a byte is received and is put into the scratchpad, the hserptr increments, so bytes will continue to collect in the scrachpad in the background, and can overflow without warning. So unless you want to log the received data, then what I think is a reliable sample code at the start of the interrupt routine, if you use the setintflags on the hserflag, or the (sub)routine which is called up on a hserflag poll, could be this:
Code:
interrupt: (or different label if not using setintflags)
hserflag=0
get ?,b?
{get ?,b?} (Number of get commands = maximum number of bytes that can be received before when no more 
                bytes are received within 50ms after the last received byte)
pause 50
if hserflag=1 then goto interrupt 'If more bytes have been received
hserptr=0 (unless you're logging received data)
 
... (more things you want to do before returning)
...
- Can I read the hserflag outside of an interrupt routine and do my own thing when I want to?
I'm not sure what you mean by "do my own thing when I want to". If it means "do my own thing to the hserflag when I want to", then you can. What will trigger the interrupt routine?

Good luck! ;)

TC
 
Last edited:

hippy

Ex-Staff (retired)
Yes, the standard download circuit can be used for the High-Speed Serial interface. The advanced circuit would be recommended if also reading ADC.
 

MartinM57

Moderator
Thanks TC and H

Re: the BAT85 in the enhanced download circuit...the manual says "The BAT85 Shokkty diode operate at a lower device voltage than the internal microcontroller diodes, providing a more accurate voltage reference" (sic) and it's drawn with a zener diode symbol.

Does it effectively clamp the serin pin at -0.2V or so when the input voltage from standard incoming RS232 voltage goes negative? What does the "...more accurate voltage reference" statement mean?

Anyway, I forgot that hserflag was a bit variable that I can access anywhere in the code ;) so as I'm writing an interrupt driven system where all the processing is done in the main loop (rather than have lots of processing inside the interrupt routine, which is bad practice) then I can read hserflag/hserptr and do what I want when I want to do it.

Ta
Martin
 

hippy

Ex-Staff (retired)
Operation of BAT85 is as you describe; it clamps at -0V2, the internal clamps at -0V3 ( or something like that ).

I think it's semantics the second part; by clamping better it allows the internal voltage reference to be more accurate to how it should be, rather than providing that voltage reference in itself.
 
Top