Thanks top204, after following your instructions by checking the generated ASM file i noticed your remarks and got to a workable solution. I have an issue with the data received. I hope you have time for another look at my code please.
Init receiver UART code: (dspic)
Code:
Input __hrsin2_port.__hrsin2_pin
High __hrsout2_port.__hrsout2_pin
U2MODE = $8808
Set U2STAbits_UTXEN
Set IEC1bits_U2RXIE
Declare Hserial2_Baud = 9600
Declare HRSOut2_Pin = PortF.5
Declare HRSIn2_Pin = PortF.4
IPC7bits_U2RXIP0 = 1 ' \
IPC7bits_U2RXIP1 = 1 ' | Priority interrupt level 7 highest priority interrupt
IPC7bits_U2RXIP2 = 1
I'm currently receiving a string with data every 500ms. The ISR routine looks like this:
Code:
Isr U2RXInterrupt
ID = 121 'Id from joystick
Toggle LedRd
If U2STAbits_OERR = 1 Then
Clear U2STAbits_OERR
GoTo ExitInterrupt2
EndIf
USART2bRx = U2RXREG
'catch start off message
If USART2bRx = ID Then
SOM = 1
Index2 = 0
EndIf
'load 8 bytes into array
If SOM = 1 Then
StrJoyStick[Index2] = USART2bRx
Inc Index2
If Index2 > 7 Then
Index2 = 0
ReceivedFromJoystick = 1
SOM = 0
EndIf
EndIf
ExitInterrupt2:
Clear IFS1bits_U2RXIF
EndIsr
The sender (18F pic) code is:
Code:
Proc SendMessage()
Dim ID As Byte
Dim StrToMain[10] As Byte
Dim wCheckSum As Word
'0'1 ID = 1
'1'0-3 Modus
'2' Command
'3' HallFwd
'4' HallRev
'5' HallLeft
'6' HallRight
'7' ChecckSum
StrToMain[0] = 121
StrToMain[1] = Modus
StrToMain[2] = Command
StrToMain[3] = HallFwd
StrToMain[4] = HallBwd
StrToMain[5] = HallLeft
StrToMain[6] = HallRight
wCheckSum = StrToMain[0] + StrToMain[1] + StrToMain[2] + StrToMain[3] + StrToMain[4] + StrToMain[5] + StrToMain[6]
bCheckSum = wCheckSum.LowByte
StrToMain[7] = bCheckSum
TMR0ON = 0
TMR0IE = 0
HRSOut Str StrToMain
Interval = 0
TMR0ON = 1
TMR0IE = 1
EndProc
If StrToMain[0 to 7] is the number 0 the receiver ISR doesnt work anymore? anything else than 0 is fine...
I will try to find why this is myself but it doesn't make sense to me