Post Go back to editing

ADUC7060 串口无法接收数据

Thread Summary

The user is experiencing issues with receiving data on the UART of the ADuC7060 microcontroller. The final answer suggests checking the configuration of P1.0 to ensure it is not conflicting with internal pull-ups/pull-downs or interrupts, and verifying the signal on P1.0 using an oscilloscope to confirm the presence of the UART signal. The solution also advises ensuring that P1.0 is not reconfigured as a GPIO after initialization.
AI Generated Content

/************************************************************************************************

Author : ADI - Apps www.analog.com/AduC7060

Date : November 2007

File : UART_IRQ.c

Hardware : ADuC706x

Description : This simple example shows how to use the UART with interrupts.
If you open a Hyperterminal window and send a charachter to the Evaluation board,
It will return a string.
Baud rate settings: 9600-N-1
*************************************************************************************************/
// Bit Definitions
#define BIT0 0x01
#define BIT1 0x02
#define BIT2 0x04
#define BIT3 0x08
#define BIT4 0x10
#define BIT5 0x20
#define BIT6 0x40
#define BIT7 0x80
#define BIT8 0x100
#define BIT9 0x200
#define BIT10 0x400
#define BIT11 0x800
#define BIT12 0x1000
#define BIT13 0x2000
#define BIT14 0x4000
#define BIT15 0x8000


#include<aduc7060.h>
# include "stdio.h"
# include "string.h"

volatile unsigned char bSendResultToUART = 0; // Flag used to indicate ADC1 resutl ready to send to UART
unsigned char szTemp[64] = ""; // Used to store ADC1 result before printing to UART
unsigned char ucTxBufferEmpty = 0; // Used to indicate that the UART Tx buffer is empty
volatile unsigned char ucRxChar = 0; // Variable to read COMRX register into in IRQ handler

int main(void)
{
unsigned char i = 0;
unsigned char nLen = 0;

POWKEY1 = 0x1;
POWCON0 = 0x78; // Set core to max CPU speed of 10.24Mhz
POWKEY2 = 0xF4;

// Initialize the UART for 9600-8-N
GP1CON = BIT0 + BIT4; // Select UART functionality for P1.0/P1.1
COMCON0 = BIT7; // Enable access to COMDIV registers
COMDIV0 = 0x21; // Set baud rate to 9600.
COMDIV1 = 0x00;
//COMDIV2 = 0x21 + BIT11; // Enable fractional divider for more accurate baud rate setting
COMCON0 = BIT0 + BIT1 + BIT2;
COMIEN0 = BIT0 + BIT1; // Enable UART interrupts when Rx full and Tx buffer empty.

IRQEN = BIT11; // Enable UART interrupt source
bSendResultToUART = 0;

sprintf ( (char*)szTemp, "Waiting for byte from PC");// Send Opening String to the UART
nLen = strlen((char*)szTemp);
for ( i = 0 ; i < nLen ; i++ ) // loop to send opening String
{
COMTX = szTemp[i];
ucTxBufferEmpty = 0;
while (ucTxBufferEmpty == 0)
{
}
}
while (1)
{
if (bSendResultToUART == 1) // Is there an ADC1 result ready for UART transmission?
{
sprintf ( (char*)szTemp, "Received Charachter was : %d,\r\n\n",ucRxChar );// Send the Received charachter to the UART
nLen = strlen((char*)szTemp);
bSendResultToUART = 0;
for ( i = 0 ; i < nLen ; i++ ) // loop to send String
{
COMTX = szTemp[i]; // Load Tx buffer
ucTxBufferEmpty = 0;
while (ucTxBufferEmpty == 0) // Wait for Tx buffer empty interrupt to occur before reloading COMTX register
{
}
}
}
}
return 0x0;
}

void IRQ_Handler(void) __irq
{
unsigned long IRQSTATUS = 0;
unsigned char ucCOMIID0 = 0;

IRQSTATUS = IRQSTA; // Read off IRQSTA register
ucCOMIID0 = COMIID0; // Read the UART IRQ ID register
if ((IRQSTATUS & BIT11) == BIT11) //UART interrupt source
{
if ((ucCOMIID0 & 0x2) == 0x2) // Transmit buffer empty
{
ucTxBufferEmpty = 1;
}
if ((ucCOMIID0 & 0x1) == 0x1) // Receive buffer Full
{
ucRxChar = COMRX; // read COMRX register
bSendResultToUART = 1; // Set flag to return a string to the PC
}
}
}

发送正常,为什么接收不到串口调试助手发送的数据,硬件验证过没有问题

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.