Hi All, When simulating an interupt from serial port RX0, I cannot succeed in affecting SBUF0 to a local variable, the watch window shows this variable to 0 even if SBUF0 is set. Here is my code : static void serial_port_0_isr (void) interrupt COM0_VECT { unsigned char data_received; if (RI != 0) { RI = 0; data_received = SBUF0; ... } } on the above code, data_received is always 0 even if SBUF0 is set. To set SBUF0, I use the serial port window from the simulator. any idea would be appreciated.
are you sure that the simulator actually uses SBUF0, and not just SBUF?
I currently compile on a EZ-USB chip which features 2 hardware serial ports, their corresponding buffers are SBUF0 & SBUF1. I forgot to mention that the generated asm seems correct !
So: how are you "simulating a serial port interrupt", then? Did you set a breakpoint in your ISR and see if execution ever actually got there? Did you step through it to observe what actually happens?
Did you set a breakpoint in your ISR and see if execution ever actually got there? Did you step through it to observe what actually happens? Yes the ISR is succesfuly called, the problem is while affecting the SBUF0 to a local register, the simulator watch window does not show me the affected value, which remains 0. The SBUF0 resgister is defined as follow in the ezregs.h sfr SBUF0 = 0x99; My code: static void serial_port_0_isr (void) interrupt COM0_VECT { unsigned char data_received; if (RI != 0) <<-- breakpoint here, the ISR is successfuly called { RI = 0; data_received = SBUF0; <<-- Here data_received is not affected ... } }
What do you do with data_received after this line? If you do nothing with it, the optimier may well have removed it! Have you looked at the generated assembler, or tried stepping at assembler level?
The next line is a test on data-received, as follow: static void serial_port_0_isr (void) interrupt COM0_VECT { unsigned char data_received; if (RI != 0) <<-- breakpoint here, the ISR is successfuly called { RI = 0; data_received = SBUF0; <<-- Here data_received is not affected ... if(data_received > 0xF8) Treat_Realtime_MIDI(data_received); ... } the line data_received = SBUF0 generates the following asm : MOV R7,SBUF0(0x99) anyway when stepping on asm, the R7 register remains to 0 while SBUF0 was 0x08 What about a memory configuration problem ? I currently use a EZUSB where only USB endpoints 0 & 1 are used, I therefore allow the compiler to use xdata memory from 0 to 0x1E40, using the modified startup.a51 code as follow: IDATALEN EQU 80H ; the length of IDATA memory in bytes. ; XDATASTART EQU 0H ; the absolute start-address of XDATA memory XDATALEN EQU 1E40H ; the length of XDATA memory in bytes. ; PDATASTART EQU 0H ; the absolute start-address of PDATA memory PDATALEN EQU 0H ; the length of PDATA memory in bytes. ; I dont know if there is a relation, I'm quite lost regarding this simulation issue !
"anyway when stepping on asm, the R7 register remains to 0 while SBUF0 was 0x08" Are you using the correct Register Bank?
well I'm new to keil and 8051, I was assuming the C compiler is able to use correct banking, which becomes transparent to the programmer, at least at the C level !? Am I wrong ? Do I have to manage banking in C ?
"Am I wrong?" Yes "Do I have to manage banking in C?" Yes - see the using keyword extension, and the REGISTERBANK Control Directive
View all questions in Keil forum