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.
OK, that looks about right. I created the following program and it works 100% correctly.
#include <reg51.h> #define COM0_VECT 4 #define SBUF0 SBUF void main (void) { SCON = 0x50; TMOD |= 0x20; TH1 = 221; TR1 = 1; ES = 1; EA = 1; while (1); } #pragma NOAREGS void Check_Midi_In_From_Con_Data_Received( unsigned char data_received) { P1 = data_received; } #pragma AREGS static void serial_port_0_isr (void) interrupt COM0_VECT { unsigned char data_received; /* ********* Received data interrupt ******** */ if (RI != 0) { // clear interupt flag RI = 0; // Now treat itr from serial port 0 data_received = SBUF0; // Treat incoming data received if(data_received > 0xF7) Check_Midi_In_From_Con_Data_Received(data_received); } /* ********* Transmited data interrupt ******** */ if (TI != 0) { TI = 0; } }
did you try simlulating this code using the cypress an21xx target processor ? I have exaclty the same problem while simultaing this code. I simply replaced the line #define SBUF0 SBUF with sfr SBUF0 = 0x99; as mentioned in the ezusb header file. I simulate the serial ITR using the serial channel 0 window from the "periferal" menu. Once opnened, I change the SBUF0 value which is the serial data received, and click on RI_0 to jump to the serial ISR. The ISR call is ok here again, while the regsiter data_received is not affected.
I forgot to mention, yes I initialized PORTCFG registers in order to use the serials ports of the ezusb: // Inititalize IOs shared functions PORTACFG = 0; // Port A is a standard GPIO PORTBCFG = 0x0C; // Port B uses RX1 & TX1 PORTCCFG = 0x0F; // Port C uses RX0 & TX0 & INT0 & INT1
After several hours spent on this, I can resume my problem as follow: What can cause R7 to not beeing affected on the following, assuming SBUF0 is a SFR register at D:0x99 which contains a value different than 0 : MOV R7,SBUF0(0x99) After steping the above, R7 is still equal to 0 ! maybe a data banking issue ? I do not use any data or code banking, also I did not included any startup.a51 file in my project. My target option uses a small memory model, and the option "use onchip Xram memory (0x000 to 0x3FF)" is checked. I did not define anything in the offchip code memory and offchip xdata memory fields since I do not use exetrnal memory Any help GREATLY appreciated. thanks again
"maybe a data banking issue?" I didn't say data banking; I was talking about Register Banks. Remember that the 8051 has 4 Banks of registers: so there's an R7 in Bank 0; an R7 in Bank 1; an R7 in Bank 2; and an R7 in Bank 3. Are you sure that you're looking at the correct Bank? Maybe R7 is changing in a different Bank?
How up to date is your version of Keil? I recall that some time ago I was having problems with the IDE showing the values of registers other than those of the currently selected register bank. You can check by using a memory window to look at data directly.
I installed the last eval version 7.07 and uvison 2.39 how can I see the four registers banks corresponding to the four R7 registers from the simulator environment ?
I checked data addresses from D:0x00 to D:0x1F which should show me all R0 to R7 registers in all 4 banks. When affecting SBUF0 to R7, none of the R7 registers is affected, I mean addresses 07, 0F, 17 and 1F left unchanged ! The PSW register value is 00 and should therfore affect the address 07. I also tried to add "using 1" in my serial port ISR definition, now the PSW value is 08, pointing to register bank 1, as expected. Unfortunately R7 in this bank is still not affected ! joe
did you try simlulating this code using the cypress an21xx target processor ? I just did. It works perfectly. Once opnened, I change the SBUF0 value which is the serial data received, and click on RI_0 to jump to the serial ISR. Well, that won't work. Writes to SBUF are sent to the transmitter. Reads from SBUF are values received. You can't write to SBUF and then read that value back. Either in the real chip on in the simulator. Have you set a breakpoint on the data_received = SBUF0; line to see what happens when you type a letter like 'A'. It works just fine. To send a character with an ACSII value higher than 0xF7 you'll probably have to use the VTREGs. Run the program, and while it's waiting for a serial character, enter S0IN = 0xF8 in the Command Window. Refer to http://www.keil.com/support/docs/2083.htm for more information on that. Jon
YES ! it works now ! I was thinking it was possible to simulate incoming serial data by simply entering them in sbuf0 field from the serial channel 0 window. Thanks to everybody for your time. joe