News:

;) This forum is the property of Proton software developers

Main Menu

RsOut/RsIn defaulted to inverted?

Started by keytapper, May 22, 2024, 06:23 AM

Previous topic - Next topic

keytapper

Hello folks,
I spent several days to learn which way I have to program a serial communication in software.
I didn't realize that the inverted mode is also a separated setting.

I got to test many systems before I discovered the culprit. For what I could know the standard is from high to low transition. So zero level is set to VCC.

Then setting a part the MCU I tested this source:
Device 12F1840
Xtal = 32
On_Hardware_Interrupt GoTo ISRoutine
#Disable HRSOut

Config1 FOSC_INTOSC, WDTE_SWDTEN, PWRTE_ON, MCLRE_OFF, CP_OFF, CPD_OFF, _
        BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PLLEN_ON, STVREN_OFF,LVP_OFF

Declare Hserial_Baud 57600
Declare HSerial_Terminator = CR
Declare Hserial_TXSTA = %00100100
Declare Hserial_RCSTA = %10010000
Declare RSOut_Mode = 0              ' using this mode to have the standard
Declare RSIn_Mode = 0               ' using this mode to have the standard
Declare Rsin_Timeout = 300
Declare RSOut_Pin = PORTA.4
Declare RSIn_Pin = PORTA.3
Declare Serial_Baud = 9600
Symbol OUT_PIN PORTA.2
Symbol GIE INTCON.7
Symbol PEIE INTCON.6
Symbol RCIE PIE1.5
Symbol RCIF PIR1.5
Symbol TXIF PIR1.4
Symbol TXIE PIE1.4
Symbol TXEN TXSTA.5
Symbol NOT_TO STATUS.4
Symbol CR 13
Symbol LF 10
Symbol TRUE 1
Symbol FALSE 0

Dim RXBUFSIZE As 32
Dim TXBUFSIZE As 32
Dim rxbuffer[RXBUFSIZE] As Byte
Dim txbuffer[RXBUFSIZE] As Byte
Dim rx_WR           As Byte System
Dim tx_RD           As Byte System
Dim tx_WR           As Byte System
Dim rx_RD           As Byte System
Dim txchar          As Byte
Dim rxchar          As Byte
Dim tmpval          As Byte
Dim flags           As Word
Dim OKflag          As flags.0

OSCCON = %01110000
WDTCON = %00011110
OPTION_REG = 0
WPUA = %00001010
LATA  = 0
$ifndef DEBUGGER
TRISA = %00100010
PORTA = 0
$else
TRISA = %00101010
PORTA = %00001000
$endif
Set GIE
Set PEIE
Set RCIE
WREG = RCREG

RsOut "Debug Ready",CR,LF
DelayMS 1000
Do
  If rx_WR <> rx_RD Then
    rxchar = rxbuffer[rx_WR]
    RsOut rxchar
    If rx_WR >= RXBUFSIZE Then
      rx_WR = 0
    Else
      Inc rx_WR
    End If
  End If
  RsIn {skip_it}, tmpval
  HSerOut [tmpval]
skip_it:
Loop
End

__hrsout1__:
  Clear GIE
  txchar = WREG
  txbuffer[tx_RD] = txchar
  Inc tx_RD
  If tx_RD >= TXBUFSIZE Then
    Clear tx_RD
  EndIf
  Set TXIE
  Set GIE
Return
'-----------------Interrupt Routine  ----------------------------------------
ISRoutine:
Context Save
  If  TXIE = 1 Then
    If TXIF = 1 Then
      TXREG = txbuffer[tx_WR]
      Inc tx_WR
      If tx_WR >= TXBUFSIZE Then
        Clear tx_WR
      EndIf
      If tx_WR = tx_RD Then
        Clear TXIE
      End If
    End If
  End If
  If RCIE = 1 Then
    If RCIF = 1 Then
      Movlw 6
      Movlb 0x03
      Andwf RCSTA,W
      Movlb 0x00
      Bnz _UART_Error
      rxbuffer[rx_WR] = RCREG
      Inc rx_WR
      If rx_WR >= RXBUFSIZE Then
        rx_WR = 0
      EndIf
      GoTo ISR_Exit
_UART_Error:
      WREG = RCREG
      Clear RCSTA.4
      Set RCSTA.4
    End If
  End If
ISR_Exit:
Context Restore
Then finally it works.
Ignorance comes with a cost