This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C8051F320 UART Issue

I know my MAX487EESA UART Transeiver chip is sending data to the recieve pin on the F320, as I can watch high and low activity on the scope. The baud rate needs to be 460800 from my device and I have it configured to 24Mhz sysclock, with a TH1 value of 0xE6. As far as I can tell I have configured everything correctly. The following code is a stripped down version to just load an array to see values. There should be at least all sorts of different values but all I get is 0x00 and 0x80. Can anyone help?

#include <cygnal\c8051f320.h>

void init_UART(void);
void Oscillator_Init(void);
void Port_IO_Init(void);
void Reset_Sources_Init(void);

sbit SMBUS_Selection = P1^5;
sbit SPI_Selection = P1^6;
sbit UART_Selection = P1^7;

unsigned int temp[50];
unsigned int v;

void main()
{
 	SMBUS_Selection = P1^5;
	SPI_Selection   = P1^6;
	UART_Selection  = P1^7;

  	P0 = 0x00;
 	P0MDOUT = 0x00; 					// Sets P0 to open drain
  	P2 = 0x00;
  	P2MDOUT = 0x00;

	PCA0MD &= ~0x40;                	// Disable Watchdog timer
  	EA = 0;								//  Enable global interrupts

	Port_IO_Init();
	Reset_Sources_Init();

	Oscillator_Init();  				// Setup SYSCLK to 24 MHz

	if (UART_Selection == 0)
	{
		init_UART();

		while (1)
		{
			while (RI0 == 0);
			RI0 = 0;
			temp[v++] = SBUF0;
			if (v == 49)
			v = 0;
		}
	}
}

void init_UART(void)
{

	TMOD      	|= 0x20;		// Timer 1 8-bitcounter/timer w auto-reload
    CKCON     	= 0x08;			// Timer 1 uses the system clock/1
    TH1     	= 0xE6;			// Timer 1 Equation17.1 BaudRate for 460800 & 24Mhz
	////TL1			= 0xFF;			// Low bytes of Timer 1
	TR1			= 1;			// Timer 1 on


	S0MODE		= 0;			// 8 bit UART with Variable Baud Rate
	RI0 		= 1;			// Recieve Flag (Clear by software)
	ES0			= 1;			// Enable UART interrupts
	SCON0 	  	|= 0x10;  		// Enable receive (REN0 is 1)
	////PS0			= 1;			// Set to high priority
}


void Oscillator_Init() 			// Initialize clock to 24 MHz
{
  int i = 0;
  CLKMUL    = 0x80;             // Clk multiplier enabled
  for (i = 0; i < 20; i++);     // Wait 5us for initialization
  CLKMUL    |= 0xC0;            // Initialize multiplier
  while ((CLKMUL & 0x20) == 0);
  CLKSEL    = 0x02;             // SYSCLK uses 4x Clk multipler/2
  OSCICN    = 0x83;             // Internal oscillator/1
}

void Port_IO_Init(void)
{
  XBR1      = 0xC0;				// Weak Pull Up Disabled and Crossbar enabled
  P1MDIN 	= 0xFF;
  P1MDOUT 	= ~0xE0;			// Sets P1.5,6,7 as open drain
  P1 		= 0xE0;				// Logic high and high impedance if out.n=0
  XBR0      = 0x07;
}

void Reset_Sources_Init()
{
    int i = 0;
    VDM0CN    = 0x80;
    for (i = 0; i < 350; i++);  // Wait 100us for initialization
    ////RSTSRC    = 0x84;
}

0