We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am reading in I2C protocol, which fills up a USB_TX_Buffer. I have that buffer in the watch window and can see the values I want filling it up, but when I to transmit it out on the UART TX pin on the F320 all I get is a steady Voltage high signal. The second bit of the code is the UART init. Anyone have any ideas?
else if (TI0) // A TX is complete, handle TX states, inside UART interrupt { TI0 = 0; // Clear transmit flag UART_TX_NDX = 0; // Reset index init_UART(); SCON0 = 0x00; while (!FLAG_UART_TXDONE) ////switch (NEXT_TX_STATE) { ////case STATE_SEND: if (UART_TX_NDX < SMBus_UART0_RX_NDX) { SBUF0 = USB_TX_Buffer[UART_TX_NDX++]; } if (UART_TX_NDX == SMBus_UART0_RX_NDX) { FLAG_UART_TXDONE = 1; } ////break; ////default: ////break; } } void init_UART(void) { TMOD |= 0x20; // Timer 1 8-bitcounter/timer w auto-reload CKCON = 0x08; // Timer 1 uses the system clock/1 TH1 = 0x30; // Timer 1 Equation17.1 BaudRate for 57600 & 24Mhz ////TL1 = 0x30; // Low bytes of Timer 1 TR1 = 1; // Timer 1 on S0MODE = 0; // 8 bit UART with Variable Baud Rate RI0 = 0; // Recieve Flag (Clear by software) ES0 = 1; // Enable UART interrupts SCON0 |= 0x10; // Enable receive (REN0 is 1) ////PS0 = 1; // Set to high priority }
init_UART(); In the ISR????????????? Erik
Yea, that was supposed to be commented out. The init_UART is called in the main program below. Still same probelm tho, still steady high voltage on P0.4 (UART TX)
void main() { char SampleCount = 0; unsigned int i; PCA0MD &= ~0x40; // Disable Watchdog timer P0 = 0x00; P0MDOUT = 0x00; // Sets P0 to open drain ////P0MDOUT |= 0x10; P2 = 0x04; P2MDIN =0xFF; P2MDOUT = 0x00; EA = 1; // Enable global interrupts USB_Init(VendorID, ProductID, ManuStr, ProdStr, SeriStr, MaxPower, PwAttributes, bcdDevice); Oscillator_Init(); // Setup SYSCLK to 24 MHz init_UART(); USB_Int_Enable(); // USB API generates interrupts SMBUS_Selection = P1^5; SPI_Selection = P1^6; UART_Selection = P1^7; // JS Init_Device(); if (SMBUS_Selection == 0) { init_Timer2(200); // 200 Hz sample rate init_Timer3(25); // SMBus SDA timeout after 25 ms init_SMBus_Master((long)400000); // 400 kHz SCK frequency // Reset the bus SMBus_ResetBus(); // Enable SMBus interrupt EIE1 |= 0x01; // Start device reading flag_DEVICE_READING = 0; // SMBus_QueryAllDevices(); while (1) { if (REG0CN & 0x40) // If USB connected send thru USB { while (flag_Timer2Running); start_Timer2(); // Wait if the device is not reading while (!flag_DEVICE_READING); // Read each device in the device address list for (i = 0; i < SMBus_DevListNDX; i++) { // Begin a read SMBus_ReadSlave(SMBus_DevAddrList[i]); // Wait for current read to finish while (flag_MODULEBUSY); } // Send data up USB if (SMBus_TotalRXNDX > 0) { flag_USB_TX_DONE = 0; // Clear USB TX flag Block_Write(&USB_TX_Buffer, SMBus_TotalRXNDX); // Send up buffer SMBus_TotalRXNDX = 0; // Clear count // Wait for write to finish while(!flag_USB_TX_DONE && flag_DEVICE_READING); } } else // No USB connection, Send thru UART { flag_DEVICE_READING = 1; init_SMBus_Master((long)400000); // 400 kHz SCK frequency while (flag_MODULEBUSY); // Issue general call to query devices on bus SMBus_QueryAllDevices(); for (i = 0; i < SMBus_DevListNDX; i++) { // Begin a read SMBus_ReadSlave(SMBus_DevAddrList[i]); // Wait for current read to finish while (flag_MODULEBUSY); } } } } else if (SPI_Selection == 0) { // SPI_Master_Init(400000); // 400 kHz SPI_Master_Init(100000); // 100 kHz while (1) { while (flag_SPI_slaveselected) { // Start transfer flag_SPI_RX_Done = 0; // Clear flag while(!flag_SPI_RX_Done) SPI0DAT = 0x00; flag_USB_TX_DONE = 0; Block_Write(&USB_TX_Buffer, USB_TX_Buffer[4]); // Send up buffer an169 while(!flag_USB_TX_DONE); } } } else if (UART_Selection == 0) { while (1) { flag_UART0_RX_Done = 0; ////while (!flag_UART0_RX_Done) ////SBUF0 = 0x00; //// EIE1 &= ~0x02; // Disable USB0 interrupt flag_USB_TX_DONE = 0; Block_Write(&USB_TX_Buffer, USB_TX_Buffer[4]); // Send up buffer an169 while(!flag_USB_TX_DONE); //// EIE1 |= 0x02; // Enable USB0 interrupt } } }
When i run the code on the processor the voltage stays steady around 3.3 volts on the transmit pin and the RX pin is around 6 volts! Is that right?
When I change the TIO part of the UART interrupt to the following code below to just output a steady value there is no probelm. Only when I try to put the USB_TX_Buffer[UART_TX_NDX++] into the SBUF0 it stops working. I put the EIEI1 &= ~0x02 to dissable the USB interrupt thinking maybe the code was going for an adventure there, but didnt help.
else if (TI0) // A TX is complete, handle TX states ----------------------- { TI0 = 0; // Clear transmit flag UART_TX_NDX = 0; // Reset index ////SCON0 = 0x00; ////TR1 = 1; while (!FLAG_UART_TXDONE) ////switch (NEXT_TX_STATE) { EIE1 &= ~0x02; // Disable USB0 interrupt ////case STATE_SEND: if (UART_TX_NDX < SMBus_UART0_RX_NDX) { ////SBUF0 = USB_TX_Buffer[UART_TX_NDX++]; SBUF0 = 0xFF; } ////if (UART_TX_NDX == SMBus_UART0_RX_NDX) ////{ //// FLAG_UART_TXDONE = 1; //// } ////break; ////default: ////break; }