xvISRRX on Q41

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
animo3d
Posts: 24
Joined: Sun Sep 18, 2011 6:02 am
Location: Monterrey Mexico

xvISRRX on Q41

Post by animo3d » Sat Jun 04, 2022 4:51 am

Hello again, I have been trying to get the most out to the Q41 Chips, and getting into a little bit of trouble, oane again kinda lost...

I was able to define simple interrupt by reading the examples posted by Jerry about the IVT module, then I found that exist is a version of the ISRRX that is supposed to work with the VIC chips, I spent hours testing, analizing and comparing the xvISRRX Library and try to make the ISRRX Help File example using the xvISRRX Library but had no results...

there is the code I am trying to make work (That oviously works weel on the older chips using the old ISRRX Lib)

Code: Select all


Device = 18F16Q41      'Automatically brings in device file 18F16Q41.bas
Clock = 64             '64MHz
Config   FEXTOSC =  HS, 
         RSTOSC = HFINTOSC_64MHZ


Include "pps.bas"
#option USART_RX = PORTB.5
#option USART_TX = PORTB.7
Include "USART.bas"

#option RX_BUFFER_SIZE = 250      
#option RX_PRIORITY = ipLow
Include "xvISRRX.bas"
 
 

// RX OnData() event...

Sub OnData()
   // ignore CR and LF...
   If ISRRX.DataByte = 13 Or ISRRX.DataByte = 10 Then
      ISRRX.ProcessByte = false
   
   // replace period with space character...
   ElseIf ISRRX.DataChar = "." Then
      ISRRX.DataChar = " "
   EndIf
End Sub


Public Sub InitPPS()
    'Module: UART pin directions
    Input(PORTB.5)    ' Make RX1 pin an input
    Output(PORTB.7)    ' Make TX1 pin an output
    'Module: UART1
    U1RXPPS = $000D    'RB5 > RX1
    RB7PPS = $0010    'TX1 > RB7
End Sub

 

' program start...

Output(PORTA.2)
Low(PORTA.2)
InitPPS()
USART.SetBaudrate(br9600)
ISRRX.Initialize(@OnData)
USART.write(13,10,"START TEST ISR",13,10) 
 

' loop forever...

While true
   DelayMS (500)
   Toggle(PORTA.2)
   ' read data from the buffer and output...
   While ISRRX.DataAvailable
      USART.Write(ISRRX.ReadByte)
   Wend
Wend 
On the terminal I got the "START TEST ISR", but when I send someting nothing happens... (on the older chip with the old ISRRX lib I got the response correctly...)
Am I doing something wrong?

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: xvISRRX on Q41

Post by Jerry Messina » Sat Jun 04, 2022 11:11 am

There's a bit more to it when using the ivt.bas module.

Try this... I modified the example to include your code.
It compiles, but it's completely untested, so if it doesn't' work let me know and I'll dig up some hardware.

Code: Select all

// xvISRRX test
device = 18F16Q41
clock = 64

// config settings
#if (_device = 18F16Q40) or (_device = 18F16Q41)
config
    FEXTOSC = OFF,      // Oscillator not enabled
    RSTOSC = HFINTOSC_64MHZ,// HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
    CLKOUTEN = OFF,     // CLKOUT function is disabled
    PR1WAY = OFF,       // PRLOCKED bit can be set and cleared repeatedly
    CSWEN = ON,         // Writing to NOSC and NDIV is allowed
    FCMEN = OFF,        // Fail-Safe Clock Monitor disabled
    FCMENP = OFF,       // Fail-Safe Clock Monitor disabled
    FCMENS = OFF,       // Fail-Safe Clock Monitor Disabled
    MCLRE = EXTMCLR,    // If LVP=0, MCLR pin is MCLR; If LVP=1, RE3 pin function is MCLR
    PWRTS = PWRT_OFF,   // PWRT is disabled
    MVECEN = OFF,       // Interrupt contoller does not use vector table to prioritze interrupts
    IVT1WAY = OFF,      // IVTLOCKED bit can be cleared and set repeatedly
    LPBOREN = OFF,      // Low-Power BOR disabled
    BOREN = SBORDIS,    // Brown-out Reset enabled , SBOREN bit is ignored
    BORV = VBOR_1P9,    // Brown-out Reset Voltage (VBOR) set to 1.9V
    ZCD = OFF,          // ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = OFF,      // PPSLOCKED bit can be set and cleared repeatedly (subject to the unlock sequence)
    STVREN = ON,        // Stack full/underflow will cause Reset
    LVP = OFF,          // Low voltage programming disabled
    XINST = OFF,        // Extended Instruction Set and Indexed Addressing Mode disabled
    WDTCPS = WDTCPS_31, // Divider ratio 1:65536; software control of WDTPS
    WDTE = SWDTEN,      // WDT enabled/disabled by SWDTEN bit
    WDTCWS = WDTCWS_7,  // window always open (100%); software control; keyed access not required
    WDTCCS = SC,        // Software Control
    BBSIZE = BBSIZE_512,// Boot Block size is 512 words
    BBEN = OFF,         // Boot block disabled
    SAFEN = OFF,        // SAF disabled
    DEBUG = OFF,        // Background Debugger disabled
    WRTB = OFF,         // Boot Block not Write protected
    WRTC = OFF,         // Configuration registers not Write protected
    WRTD = OFF,         // Data EEPROM not Write protected
    WRTSAF = OFF,       // SAF not Write Protected
    WRTAPP = OFF,       // Application Block not write protected
    CP = OFF            // PFM and Data EEPROM code protection disabled
#endif

include "intosc.bas"
#option DIGITALIO_INIT = true   // automatically call SetAllDigital at startup
include "setdigitalio.bas"

include "pps.bas"
include "ivt.bas"

//
// If you are using a device with PPS mapped pins then set the #options
// 'USARTx_TX' and 'USARTx_RX' to match the port pins you're using before
// including the USARTx.bas module... you'll still have to setup the PPS
// NOTE: if the pins have analog capability it is up to the user to set 
// the respective pins to digital IO mode (ie setalldigital)
//
#option USART_RX = PORTB.5
#option USART_TX = PORTB.7
include "USART.bas"

#option RX_BUFFER_SIZE = 128
#option RX_PRIORITY = 1             // high-priority (default)
include "xvISRRX.bas"

const
    CR = 13,
    LF = 10
    
dim rxc as byte

// on RX data event, replace period with underscore...
event OnData()
   // ignore CR and LF...
   if (ISRRX.DataByte = CR) or (ISRRX.DataByte = LF) then
      ISRRX.ProcessByte = false
   // replace period with space character...
   elseif (ISRRX.DataChar = ".") then
      ISRRX.DataChar = "_"
   endif   
end event

// assign uart pps pins (Q41)
sub assign_usart_pps()
    pps.unlock()
    pps.assign_output(RB7PPS, PPS_UART1_TX)     // PORTB.7
    pps.assign_input(U1RXPPS, PPS_PORTB, 5)     // PORTB.5
end sub

//----------------------------------------------------------------------------
// main program entry begins here
//----------------------------------------------------------------------------
main:

output(PORTA.2)
low(PORTA.2)

assign_usart_pps()

// init interrupt controller
// set vector table to use ivt_table (see below)
SET_IVTBASE(ivt_table)

// set baudrate
SetBaudrate(br9600)
ISRRX.Initialize(OnData)

USART.write(CR, LF, "START TEST ISR", CR, LF)

// enable high-priority interrupts
ENABLE_INTERRUPT()


// loop forever...
while true
    // wait and gather up incoming chars... simulates being busy
    // max chars depend on the size of the input buffer and speed
    delayms(500)
    toggle(PORTA.2)

    // report an error...
    if ISRRX.Overrun() then
        USART.WriteByte(byte("*"))
    endif

    // read data from the buffer and output...
    while ISRRX.DataAvailable()
        rxc = ISRRX.ReadByte()
        USART.WriteByte(rxc)
    end while
end while

//----------------------------------------------------------------------------
// IVT table initialization
//----------------------------------------------------------------------------

// create the primary IVT and add interrupt handlers to the table
// (IRQ_ISRRX and ISRRXIsr are defined in xvISRRX.bas)
CREATE_IVT(ivt_table)
SET_IVT_HANDLER(IRQ_ISRRX, ISRRXIsr)
END_IVT()

//----------------------------------------------------------------------------
// end IVT table
//----------------------------------------------------------------------------

Post Reply