• AVR Freaks

Helpful ReplyHot!U1RXREG has incorrect values, but code works fine when someone else programs the pic

Author
int_i
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2020/07/29 04:42:05
  • Location: 0
  • Status: offline
2020/08/05 12:09:09 (permalink)
0

U1RXREG has incorrect values, but code works fine when someone else programs the pic

So, I got some code (12ch_control.txt ) which, after asking multiple times, I was assured works, and is the version the person used when programing the dsPIC30F himself. I've tested the code, and the device responds to the data properly.
 
However, when I try to program the device with the same code, while debugging, the RX interrupt is raised, but the content of U1RXREG is incorrect - either always 0 or 0x42 (it switched from 0 to 0x42 and back to 0 again between debug sessions, not sure why).
 
I have used MPLAB X IDE v5.35 with a PICkit 3 and XC16, as well as MPLAB v8.92 with PICkit 2 and both XC16 and MC30 to no avail.
 
I'm very new to PIC programing but I can't imagine how this could be possible, that it works for one person (also using some version of MPLAB v8 and a PICkit 2) and not the other. I'm stumped.
 
Also attached is the Python script I used to send data to the PIC. Every byte I send causes the IDE to halt at the breakpoint I set (where the value of U1RXREG is assigned to the variable) and as I've said, the content is just wrong.
 
Also, note that there's a bug - the array size allocated for received data is too small, and read/write operations are performed beyond the boundary. I tried fixing it when I used MPLAB X but it didn't solve any problems, though come to think of it, I didn't do "Clean and build" (just "Make and program device"), but again - I was assured that this is indeed the code he used which actually works when he programs the device... so I'm using the code I was sent as is because I don't want to risk adding a new problem when I still have this one to solve...
 
Any help would be very much appreciated!
 
#1
NorthGuy
Super Member
  • Total Posts : 6291
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: U1RXREG has incorrect values, but code works fine when someone else programs the pic 2020/08/06 09:57:39 (permalink) ☄ Helpfulby int_i 2020/08/07 12:00:20
4.67 (3)
The URXREG is a volatile register. Every time you read it it returns a new value. Therefore, if you read it with debugger, you don't get the same value as your program gets. Also your program does not get the same value as it would get without you watching the register in the debugger. Therefore, don't watch URXREG in the debugger.
#2
int_i
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2020/07/29 04:42:05
  • Location: 0
  • Status: offline
Re: U1RXREG has incorrect values, but code works fine when someone else programs the pic 2020/08/07 12:00:08 (permalink)
0
NorthGuy
The URXREG is a volatile register. Every time you read it it returns a new value. Therefore, if you read it with debugger, you don't get the same value as your program gets. Also your program does not get the same value as it would get without you watching the register in the debugger. Therefore, don't watch URXREG in the debugger.


That's good to know. I'll read the variable it's assigned to. I haven't tested the setup without debugging since switching to MPLAB v8 (had some problems with MPLAB X). I'll update on the issue after I've tested it (I'll also look into registers related to errors just to be absolutely sure it's not due to some error that affects communication). thank you.
#3
int_i
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2020/07/29 04:42:05
  • Location: 0
  • Status: offline
Re: U1RXREG has incorrect values, but code works fine when someone else programs the pic 2020/08/23 05:49:03 (permalink)
4.5 (2)
on the off chance someone comes across this, I haven't found a satisfactory solution (haven't put much effort into finding one), but the solution I found was to use the PICkit2 as a programmer (not debugger), choose "Release" build configuration (rather than debug). Still had some issues (code wouldn't always run unless the PICkit was connected to it and to the computer as well), but those were solved by unchecking any box that had something to do with generation of debug information/symbols/etc. in the project properties.
 
Good luck, and may Turing have mercy on your soul.
#4
Jump to:
© 2020 APG vNext Commercial Version 4.5