I use 413 to simulate serial port data transmission and reception, but can only receive single bytes. When debugging with serial port assistant, I find that the bytes sent by 413 to PC are incorrect.
For example, the serial port assistant sends 0xaa to 413, and 413 sends 0xaa back to PC after receiving it, but the serial port assistant receives 0x00 or other data.
Why? How can I achieve the correct transmission and reception of a string of data?
The program is as follows (the crystal oscillator is 32768, connected to pins 8 and 9 of 413):
#include
#define RXD 0x0002 // RXD on P1.1
#define TXD 0x0002 // TXD on P2.1
#define RS485 0x0001 //enable 485 on P2.0
// Conditions for 2400 Baud SW UART, ACLK = 32768
#define Bitime_5 0x06 // ~ 0.5 bit length + small adjustment
#define Bitime 0x0E // 427us bit length ~ 2341 baud
unsigned int RXTXData;
unsigned char BitCnt;
void Delay(unsigned int i);
void TX_Byte(void);
void RX_Ready(void);
void main(void)
{
WDTC TL = WDTPW + WDTHOLD; // Stop watchdog timer
FLL_CTL0 |= 85; P2OUT
&= ~RS485; _EINT(); // Mainloop for(;;) { RX_Ready ( ) ;
// UART ready to RX one Byte _BIS_SR(LPM3_bits + GIE); // Enter LPM3 Until character RXed TX_Byte(); // TX Back RXed Byte Received } } void Delay(unsigned int i) { unsigned char j; for (j = 0;j< 5; j ++) while(i--); } // Function Transmits Character from RXTXData Buffer void TX_Byte(void) { P2OUT |= RS485; Delay(10); P2OUT &= ~RS485; BitCnt = 0x0A; // Load Bit counter, 8data + ST/SP CCR0 = TAR; // Current state of TA counter CCR0 += Bitime; // Some time till first bit RXTXData |= 0x0100; // Add mark stop bit to RXTXData RXTXData = RXTXData << 1; // Add space start bit CCTL0 = OUTMOD0 + CCIE; // TXD = mark = idle while(CCTL0 & CCIE); // Wait for TX completion } // Function Readies UART to Receive Character into RXTXData Buffer void RX_Ready(void) { BitCnt = 0x08; // Load Bit counter CCTL0 = SCS+ CCIS0 + OUTMOD0 + CM1 + CAP + CCIE; // Sync, Neg Edge, Capture } // Timer A0 interrupt service routine interrupt [TIMERA0_VECTOR] void TimerA0_ISR(void) {
CCR0 += Bitime; // Add Offset to CCR0
// RX------------------------------------ -----------------------------------------------
if(CCTL0 & CCIS0) // RX on CCI0B?
{
if(CCTL0 & CAP) // Capture mode = start bit edge
{
CCTL0 &= ~CAP; // Capture to compare mode
CCR0 += Bitime_5;
}
else
{
RXTXData = RXTXData >> 1;
if(CCTL0 & SCCI) / / Get bit waiting in receive latch
RXTXData |= 0x80;
BitCnt --; // All bits RXed?
if(BitCnt == 0)
//>>>>>>>>>> Decode of Received Byte Here <<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
CCTL0 &= ~CCIE; // All bits RXed, disable interrupt
_BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR)
}
//>>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<
}
}
// TX---------------------- -------------------------------------------------
else
{
if(BitCnt == 0)
CCTL0 &= ~CCIE; // All bits TXed, disable interrupt
else
{
CCTL0 |= OUTMOD2; // TX Space
if(RXTXData & 0x0001)
CCTL0 &= ~OUTMOD2; // TX Mark
RXTXData = RXTXData >> 1;
BitCnt--;
}
}
}
Please give me some advice!!!
lsdfae18
2006-10-13, 11:49
Refer to this program
#define RXD 0x02 // RXD on P1.1
#define TXD 0x01 // TXD on P1.0
// Conditions for 2400 Baud SW UART, ACLK = 32768
#define Bitime_5 0x06 // ~ 0.5 bit length + small adjustment(14/2=7)
#define Bitime 0x0E // 427us bit length ~ 2341 baud (14/32768=427.246us,32768/14=2340.571428)
unsigned int RXTXData;
unsigned char BitCnt; //bit count
void TX_Byte (void);
void RX_Ready (void);
// M.Buccini
// Texas Instruments, Inc
// March 2002
//************************************************ **********************************
#include
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer (turn off the watchdog module)
FLL_CTL0 |= XCAP14PF; // Configure load caps (configure oscillator capacitance)
CCTL0 = OUT; // TXD Idle as Mark (capture/compare register 0: output high level)
TACTL = TASSEL0+MC1; // ACLK, continous mode
P1SEL = TXD + RXD; // PP1.0/1 TA0 for TXD/RXD function
P1DIR = TXD; // TXD output on P1
// Mainloop
for (;;)
{
RX_Ready(); // UART ready to RX one Byte
_BIS_SR(LPM3_bits+GIE); // Enter LPM3 Until character RXed
TX_Byte(); // TX Back RXed Byte Received
}
}
// Function Transmits Character from RXTXData Buffer
void TX_Byte (void)
{
BitCnt = 0xA; // Load Bit counter, 8data + ST/SP
CCR0 = TAR; // Current state of TA counter(Timer counter current value is placed in compare register)
CCR0 += Bitime; // Some time till first bit(Push back one bit time)
RXTXData |= 0x100; // Add mark stop bit to RXTXData(Fill stop bit)
RXTXData = RXTXData << 1; // Add space start bit(Fill start bit)
CCTL0 = OUTMOD0+CCIE; // TXD = mark = idle(Set output mode, enable interrupt)
while ( CCTL0 & CCIE ); // Wait for TX completion(Wait for TX completion)
}
// Function Readies UART to Receive Character into RXTXData Buffer
void RX_Ready (void)
{
BitCnt = 0x8; // Load Bit counter(Receive 8 bits)
CCTL0 = SCS+CCIS0+OUTMOD0+CM1+CAP+CCIE; // Sync, Neg Edge, Capture
//(CCIxB pin synchronous falling edge capture, set output mode, enable interrupt)
}
// Timer A0 interrupt service routine
interrupt[TIMERA0_VECTOR] void Timer_A (void)
{
CCR0 += Bitime; // Add Offset to CCR0 (next timing time is 1 bit time)
// RX (receive byte)
if (CCTL0 & CCIS0) // RX on CCI0B? (If CCI0B is the capture input pin)
{
if( CCTL0 & CAP ) // Capture mode = start bit edge (If it is in capture mode, it is waiting for the start bit)
{
CCTL0 &= ~ CAP; // Switch from capture to compare mode (Change to compare mode after getting the start bit)
CCR0 += Bitime_5; //Change the timing position to the middle of the bit (add half a bit time)
}
else
{
RXTXData = RXTXData >> 1; //The low bit is received firstif
(CCTL0 & SCCI) // Get bit waiting in receive latch
RXTXData |= 0x80; //What is latched in SCCI is the signal on the input pin when the comparison is equal
BitCnt --; // All bits RXed? //Decrease the bit count by 1
if ( BitCnt == 0) //Has one byte been received?
//>>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
CCTL0 &= ~ CCIE; // All bits RXed,disable interrupt (disable interrupt after receiving a byte)
_BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR) (prepare to exit low power mode)
}
//>>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
}
// TX (send byte, OUTMOD0 is set before entering the transmit interrupt)
else
{
if ( BitCnt == 0) //All bits TXed
, disable interrupt
else
{
CCTL0 |= OUTMOD2; // TX Space (output mode OUTMOD2+OUTMOD0: reset)
if (RXTXData & 0x01)
CCTL0 &= ~ OUTMOD2; // TX Mark (output mode OUTMOD0: set)
RXTXData = RXTXData >> 1; //Low bit first
BitCnt --; //bit count
}
}
}
Keywords:MSP430
Reference address:MSP430 simulated serial port program
For example, the serial port assistant sends 0xaa to 413, and 413 sends 0xaa back to PC after receiving it, but the serial port assistant receives 0x00 or other data.
Why? How can I achieve the correct transmission and reception of a string of data?
The program is as follows (the crystal oscillator is 32768, connected to pins 8 and 9 of 413):
#include
#define RXD 0x0002 // RXD on P1.1
#define TXD 0x0002 // TXD on P2.1
#define RS485 0x0001 //enable 485 on P2.0
// Conditions for 2400 Baud SW UART, ACLK = 32768
#define Bitime_5 0x06 // ~ 0.5 bit length + small adjustment
#define Bitime 0x0E // 427us bit length ~ 2341 baud
unsigned int RXTXData;
unsigned char BitCnt;
void Delay(unsigned int i);
void TX_Byte(void);
void RX_Ready(void);
void main(void)
{
WDTC TL = WDTPW + WDTHOLD; // Stop watchdog timer
FLL_CTL0 |= 85; P2OUT
&= ~RS485; _EINT(); // Mainloop for(;;) { RX_Ready ( ) ;
// UART ready to RX one Byte _BIS_SR(LPM3_bits + GIE); // Enter LPM3 Until character RXed TX_Byte(); // TX Back RXed Byte Received } } void Delay(unsigned int i) { unsigned char j; for (j = 0;j< 5; j ++) while(i--); } // Function Transmits Character from RXTXData Buffer void TX_Byte(void) { P2OUT |= RS485; Delay(10); P2OUT &= ~RS485; BitCnt = 0x0A; // Load Bit counter, 8data + ST/SP CCR0 = TAR; // Current state of TA counter CCR0 += Bitime; // Some time till first bit RXTXData |= 0x0100; // Add mark stop bit to RXTXData RXTXData = RXTXData << 1; // Add space start bit CCTL0 = OUTMOD0 + CCIE; // TXD = mark = idle while(CCTL0 & CCIE); // Wait for TX completion } // Function Readies UART to Receive Character into RXTXData Buffer void RX_Ready(void) { BitCnt = 0x08; // Load Bit counter CCTL0 = SCS+ CCIS0 + OUTMOD0 + CM1 + CAP + CCIE; // Sync, Neg Edge, Capture } // Timer A0 interrupt service routine interrupt [TIMERA0_VECTOR] void TimerA0_ISR(void) {
CCR0 += Bitime; // Add Offset to CCR0
// RX------------------------------------ -----------------------------------------------
if(CCTL0 & CCIS0) // RX on CCI0B?
{
if(CCTL0 & CAP) // Capture mode = start bit edge
{
CCTL0 &= ~CAP; // Capture to compare mode
CCR0 += Bitime_5;
}
else
{
RXTXData = RXTXData >> 1;
if(CCTL0 & SCCI) / / Get bit waiting in receive latch
RXTXData |= 0x80;
BitCnt --; // All bits RXed?
if(BitCnt == 0)
//>>>>>>>>>> Decode of Received Byte Here <<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
CCTL0 &= ~CCIE; // All bits RXed, disable interrupt
_BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR)
}
//>>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<
}
}
// TX---------------------- -------------------------------------------------
else
{
if(BitCnt == 0)
CCTL0 &= ~CCIE; // All bits TXed, disable interrupt
else
{
CCTL0 |= OUTMOD2; // TX Space
if(RXTXData & 0x0001)
CCTL0 &= ~OUTMOD2; // TX Mark
RXTXData = RXTXData >> 1;
BitCnt--;
}
}
}
Please give me some advice!!!
lsdfae18
2006-10-13, 11:49
Refer to this program
#define RXD 0x02 // RXD on P1.1
#define TXD 0x01 // TXD on P1.0
// Conditions for 2400 Baud SW UART, ACLK = 32768
#define Bitime_5 0x06 // ~ 0.5 bit length + small adjustment(14/2=7)
#define Bitime 0x0E // 427us bit length ~ 2341 baud (14/32768=427.246us,32768/14=2340.571428)
unsigned int RXTXData;
unsigned char BitCnt; //bit count
void TX_Byte (void);
void RX_Ready (void);
// M.Buccini
// Texas Instruments, Inc
// March 2002
//************************************************ **********************************
#include
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer (turn off the watchdog module)
FLL_CTL0 |= XCAP14PF; // Configure load caps (configure oscillator capacitance)
CCTL0 = OUT; // TXD Idle as Mark (capture/compare register 0: output high level)
TACTL = TASSEL0+MC1; // ACLK, continous mode
P1SEL = TXD + RXD; // PP1.0/1 TA0 for TXD/RXD function
P1DIR = TXD; // TXD output on P1
// Mainloop
for (;;)
{
RX_Ready(); // UART ready to RX one Byte
_BIS_SR(LPM3_bits+GIE); // Enter LPM3 Until character RXed
TX_Byte(); // TX Back RXed Byte Received
}
}
// Function Transmits Character from RXTXData Buffer
void TX_Byte (void)
{
BitCnt = 0xA; // Load Bit counter, 8data + ST/SP
CCR0 = TAR; // Current state of TA counter(Timer counter current value is placed in compare register)
CCR0 += Bitime; // Some time till first bit(Push back one bit time)
RXTXData |= 0x100; // Add mark stop bit to RXTXData(Fill stop bit)
RXTXData = RXTXData << 1; // Add space start bit(Fill start bit)
CCTL0 = OUTMOD0+CCIE; // TXD = mark = idle(Set output mode, enable interrupt)
while ( CCTL0 & CCIE ); // Wait for TX completion(Wait for TX completion)
}
// Function Readies UART to Receive Character into RXTXData Buffer
void RX_Ready (void)
{
BitCnt = 0x8; // Load Bit counter(Receive 8 bits)
CCTL0 = SCS+CCIS0+OUTMOD0+CM1+CAP+CCIE; // Sync, Neg Edge, Capture
//(CCIxB pin synchronous falling edge capture, set output mode, enable interrupt)
}
// Timer A0 interrupt service routine
interrupt[TIMERA0_VECTOR] void Timer_A (void)
{
CCR0 += Bitime; // Add Offset to CCR0 (next timing time is 1 bit time)
// RX (receive byte)
if (CCTL0 & CCIS0) // RX on CCI0B? (If CCI0B is the capture input pin)
{
if( CCTL0 & CAP ) // Capture mode = start bit edge (If it is in capture mode, it is waiting for the start bit)
{
CCTL0 &= ~ CAP; // Switch from capture to compare mode (Change to compare mode after getting the start bit)
CCR0 += Bitime_5; //Change the timing position to the middle of the bit (add half a bit time)
}
else
{
RXTXData = RXTXData >> 1; //The low bit is received firstif
(CCTL0 & SCCI) // Get bit waiting in receive latch
RXTXData |= 0x80; //What is latched in SCCI is the signal on the input pin when the comparison is equal
BitCnt --; // All bits RXed? //Decrease the bit count by 1
if ( BitCnt == 0) //Has one byte been received?
//>>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
CCTL0 &= ~ CCIE; // All bits RXed,disable interrupt (disable interrupt after receiving a byte)
_BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR) (prepare to exit low power mode)
}
//>>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
}
// TX (send byte, OUTMOD0 is set before entering the transmit interrupt)
else
{
if ( BitCnt == 0) //All bits TXed
, disable interrupt
else
{
CCTL0 |= OUTMOD2; // TX Space (output mode OUTMOD2+OUTMOD0: reset)
if (RXTXData & 0x01)
CCTL0 &= ~ OUTMOD2; // TX Mark (output mode OUTMOD0: set)
RXTXData = RXTXData >> 1; //Low bit first
BitCnt --; //bit count
}
}
}
Previous article:MSP430F149-Using IO interrupt mode to implement key detection program
Next article:MSP430 P1.1 P1.2 P1.3 Second function
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
Guess you like
- I have published some theoretical articles before. Today I will simulate and verify the real theoretical data.
- SensorTile.box Sound Control LED Brightness
- Automobile complete vehicle EMC testing, complete vehicle electromagnetic compatibility testing, automobile parts EMC testing
- Motor control video FOC sensorless
- Interrupt controller of C6678 developed by DSP
- Apply for free evaluation: Anxinke WiFi + Bluetooth audio development board ESP32-Audio-Kit!
- [Dry goods sharing] Lithium battery power supply circuit design (boost, charging management, etc.)
- [Register now, see you in Guangzhou on February 25, 2019! ] World Peace Group WPI / GDSM Visual Retail Summit
- Thank you for being there +2019
- What are the high frequency characteristics of capacitors?