$regfile = "xm192a3udef.dat"
$hwstack = 800
$swstack = 800
$framesize = 800
Osc_dfllctrl.0 = 1
Dfllrc32m_ctrl.0 = 1 'enable CALIBRATION
$crystal = 48000000
Config Osc = Enabled , 32mhzosc = Disabled
Osc_pllctrl = &B00_0_11000
Set Osc_ctrl.4 ' PLL enable
Bitwait Osc_status.4 , Set 'Check if PLL is ready
Config Sysclock = Pll , Prescalea = 1 , Prescalebc = 1_1 ' configure the systemclock ---> use PLL
Waitms 2
'Com1 - Uart_c0 PORTC.3 PORTC.2 SERIALIN or SERIALIN0
'COM2 - UART_C1 PORTC.7 PORTC.6 SERIALIN1
'COM3 - UART_D0 PORTD.3 PORTD.2 SERIALIN2
'COM4 - UART_D1 PORTD.7 PORTD.6 SERIALIN3
'Com5 - Uart_e0 Porte.3 Porte.2 Serialin4
'COM6 - UART_E1 PORTE.7 PORTE.6 SERIALIN5
'COM7 - UART_F0 PORTF.3 PORTF.2 SERIALIN6
'Com8 - Uart_f1 Portf.7 Portf.6 Serialin7
'UARTS:
'Trigsrc Base Value Group Configuration Description
'0x4b Usartc0 Usart C0 Dma Triggers Base Value
'0x4e Usartc1 Usart C1 Dma Triggers Base Value
'0x6b Usartd0 Usart D0 Dma Triggers Base Value
'0x6e Usartd1 Usart D1 Dma Triggers Base Value
'0x8b Usarte0 Usart E0 Dma Triggers Base Value
'0x8e Usarte1 Usart E1 Dma Triggers Base Value
'0xab Usartf0 Usart F0 Dma Triggers Base Value
'0xae Usartf1 Usart F1 Dma Triggers Base Value
'TRGSRC offset value Group Configuration Description
'0x00 RXC Receive complete
'0x01 DRE Data Register Empty
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled
'====Dummy Data ====
'&123456789012345678901234567890123456789012345678901234567890 Sample message sent from Terminal
'====Config USART ====
Config Serialin6 = Buffered , Size = 3 , Bytematch = &H26 '&
'uses _rs232inbuf7(size) SRAM space
Config Com7 = 57600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "COM7:" For Binary As #2
Dim Payload(60) As Byte , I As Byte , Uart_rx As Byte , Uart_tx As Byte 'Host TX Payload
'====Config DMA ====
Config Dma = Enabled , Doublebuf = Disabled , Cpm = Rr
'RX
Config Dmach0 = Enabled , Burstlen = 1 , Chanrpt = Enabled , Tci = Lo , Eil = Off , Singleshot = Enabled , Trigger = &HAB , Btc = 50 , Repeat = 1 , _
Dar = Transaction , Dam = Inc , Dadr = Varptr(payload(1)) , _
Sar = Burst , Sam = Fixed , Sadr = Varptr(usartf0_data)
'NOTE: By Defalut, this Config statement will set up the first RX msg reception and throw the ISR (you will see all Zeros in first Payload)
Dma_ch0_ctrla.7 = 0 'force initial wait for Bytematch
On Dma_ch0 Dmach0_isr
'TX
Config Dmach1 = Enabled , Burstlen = 1 , Chanrpt = Enabled , Tci = Lo , Eil = Off , Singleshot = Enabled , Trigger = &HAC , Btc = 50 , Repeat = 1 , _
Sar = Transaction , Sam = Inc , Sadr = Varptr(payload(1)) , _
Dar = Burst , Dam = Fixed , Dadr = Varptr(usartf0_data)
'On Dma_ch1 Dmach1_isr
Enable Interrupts
'====M a i n ====
Do
Config Powermode = Idle 'DMA will continue to receive UART Data while in Idle mode
If Uart_rx = 2 Then
Print #2 , Chr(13) ; Chr(13) ; Chr(10) ; "Serial Buffer Msg Rcvd: " ;
For I = 1 To 3 : Print #2 , Hex(_rs232inbuf7(i)) ; " " ; : Next
Print #2 , Chr(13) ; Chr(10) ; "DMA Msg Rcvd: ";
Dma_ch1_ctrla.7 = 1 'DMA TX to Terminal
Enable Usartf0_rxc 'Restart Bytematch
Uart_rx = 0
Clear Serialin6 'Clear Buffer
For I = 1 To 3 : _rs232inbuf7(i) = 0 : Next
End If
Loop
End
Serial6charmatch:
'Pushall
Dma_ch0_ctrla.7 = 1 'Start DMA RX
Disable Usartf0_rxc 'Disable UART RX, and let DMA receive rest of message
Uart_rx = 1
'Popall
Return
Dmach0_isr:
If Dma_intflags.0 = 1 Then 'DMA Channel 0 Transaction Interrupt
Dma_intflags.0 = 1 'Clear Interrupt
Incr Uart_rx 'set flag
End If
Return
Dmach1_isr:
If Dma_intflags.1 = 1 Then 'DMA Channel 1 Transaction Interrupt
Dma_intflags.1 = 1 'Clear interrupt
Uart_tx = 1 'set flag
End If
Return
|