Hi, I'm a Dutch student busy with my in internship where I have to make an application with a Philips P8xCL883 microcontroller. I would like to use UART to send and receive strings from a PC, but I can not get this to work properly. I searched the web for some interrupt driver routines and found some very nice ones, but implementing these caused some weird problems. I set the baudrate to 9600, but I can only receive chars when (on the PC) I send them with 28800 baud. If I search the datasheet of the P8xCL883 I did set the prescaler to the right value and I am using the right oscillator. The chars I then receive have a problem as well. For instance, if I send a "b" (binairy 01100010) I receive this as a 11000010. Hereby the 4th bit from the left should not be there and bits 1-3 should be shifted to the right 1 position. This happens with every char I receive. My mentor here can not help me with this and after a week of trying, I do not know where to look anymore. I hope anyone can give me some clues so that I can get this communication to work. Thanks in advance, Terry. The P8xCL883 runs on a 3.58 MHz crystal, which is different from a standard 8051. Using the prescaler I should be able to set the frequency for the baudrate, but this does not work for me. A datasheet is available from: http://www-us.semiconductors.philips.com/acrobat/datasheets/P8XCL883_CL884_2.pdf
And the header file, I took the headerfile for a 8051 from the Keil include directory and adjusted it according the datasheet from the P8xCL883: /* BYTE Register */ sfr P0 = 0x80; sfr SP = 0x81; sfr DPL = 0x82; sfr DPH = 0x83; sfr PCON = 0x87; sfr TCON = 0x88; sfr TMOD = 0x89; sfr TL0 = 0x8A; sfr TL1 = 0x8B; sfr TH0 = 0x8C; sfr TH1 = 0x8D; sfr P1 = 0x90; sfr S0CON = 0x98; sfr S0BUF = 0x99; sfr P3 = 0xB0; sfr PSW = 0xD0; sfr ACC = 0xE0; sfr B = 0xF0; /* SFR's added from the datasheet */ sfr P0CFGA = 0x8E; sfr P0CFGB = 0x8F; sfr P1CFGA = 0x9E; sfr P1CFGB = 0x9F; sfr LGF = 0xA1; sfr HGF = 0xA2; sfr ALTP = 0xA3; sfr WDCON = 0xA5; sfr IEN0 = 0xA8; sfr COMP2L = 0xAA; sfr COMP2H = 0xAB; sfr IP0 = 0xB8; sfr P3CFGA = 0xBE; sfr P3CFGB = 0xBF; sfr IRQ1 = 0xC0; sfr P4 = 0xC1; sfr T2CON = 0xC8; sfr RCAP2L = 0xCA; sfr RCAP2H = 0xCB; sfr TL2 = 0xCC; sfr TH2 = 0xCD; sfr MBUF = 0xD1; sfr MSTAT = 0xD2; sfr MCON = 0xD3; sfr OAL = 0xD4; sfr OAH = 0xD5; sfr ODATA = 0xD6; sfr OTEST = 0xD7; sfr S1CON = 0xD8; sfr S1STA = 0xD9; sfr S1DAT = 0xDA; sfr S1ADR = 0xDB; sfr OISYS = 0xDC; sfr ISE1 = 0xE1; sfr RSTAT = 0xE6; sfr IEN1 = 0xE8; sfr IX1 = 0xE9; sfr IEN2 = 0xF1; sfr LVDCON = 0xF2; sfr IP1 = 0xF8; sfr IP2 = 0xF9; sfr EECON = 0xFB; sfr WDTIM = 0xFF; sfr PRESC = 0xF3; /* BIT Register */ /* PSW */ sbit CY = 0xD7; sbit AC = 0xD6; sbit F0 = 0xD5; sbit RS1 = 0xD4; sbit RS0 = 0xD3; sbit OV = 0xD2; sbit P = 0xD0; /* TCON */ sbit TF1 = 0x8F; sbit TR1 = 0x8E; sbit TF0 = 0x8D; sbit TR0 = 0x8C; sbit IE1 = 0x8B; sbit IT1 = 0x8A; sbit IE0 = 0x89; sbit IT0 = 0x88; /* IEN0 */ // Changed from IE sbit EA = 0xAF; sbit ET2 = 0xAE; sbit ES = 0xAD; sbit ES0R = 0xAC; // Enable interrupt UART receive sbit ET1 = 0xAB; sbit EX1 = 0xAA; sbit ET0 = 0xA9; sbit EX0 = 0xA8; /* IEN2 */ sbit ES0T = 0xF3; // Enable interrupt UART transmit /* IP0 */ // Changed from IP sbit PS = 0xBC; sbit PT1 = 0xBB; sbit PX1 = 0xBA; sbit PT0 = 0xB9; sbit PX0 = 0xB8; /* P3 */ sbit RD = 0xB7; sbit WR = 0xB6; sbit T1 = 0xB5; sbit T0 = 0xB4; sbit INT1 = 0xB3; sbit INT0 = 0xB2; sbit TXD = 0xB1; sbit RXD = 0xB0; /* S0CON */ sbit SM0 = 0x9F; sbit SM1 = 0x9E; sbit SM2 = 0x9D; sbit REN = 0x9C; sbit TB8 = 0x9B; sbit RB8 = 0x9A; sbit TI = 0x99; sbit RI = 0x98; Sorry for messing up the layout, but the messages are of a limited length
After some calculations and some testing I found that setting the PRESC register to 34h seems to solve the receive problem. Reception works for 9600 baud. The formula: Baud Rate = ((2^SMOD) / 32) * Fpsc * (1 / ((2^PTWD) * (3^P3)) is used, I take SMOD = 0, Fpsc = 1:5 Fosc = 715909, PTWD = 6 and P3 = 0. This gives a baud rate of 10240 baud, and perfect reception with 9600 baud sending from the PC. Setting Fpsc to 1:3 = 1193181.667, PTWD = 5 and P3 = 1 should give a baud rate of 9216, but does not work, reception of 9600 baud chars is not working properly. Very weird, but reception is working, I am happy as I can be today.
After reception works ok, I started to work on transmitting chars. It seems that I can not set the TI bit manual (or in software) to enter the interrupt routine. Not by setting the TI = 1; nor by S0CON |= 0x02;. Is there a way around this, so that I can enter the interrupt routine without setting the TI bit?
After reception works ok, I started to work on transmitting chars. It seems that I can not set the TI bit manual (or in software) to enter the interrupt routine. Not by setting the TI = 1; nor by S0CON |= 0x02; (S0CON = SM0, SM1, SM2, REN, TB8, RB8, TI, RI). Is there a way around this, so that I can enter the interrupt routine without setting the TI bit?