MSP430fr6989 serial port DMA sending experimental routine
[Copy link]
These two registers are mainly used:
DMACTL0 is used to select DMA channels; such as ADC12, serial port, IIC, SPI. Here is one more sentence: DMA is a method, while SPI, IIC, serial port, etc. are peripherals. The two are not the same concept.
DMAxCTL is used for detailed DMA settings; this is the key point!!! DMAxCTL includes:
DMADT: Select whether the transfer mode is a single byte or a block transfer; in this example, a simple single byte transfer is selected;
DMADSTINCR: decomposition of the word DMA dest increase means the data transfer destination address increase mode; there are four options 0 1 2 3, 0 and 1 represent the address does not change, 2 represents the address decrease, 3 represents the address increase;
DMASRCINCR: Also decomposes DMA src increase, that is, the data source address increase method. At this point, if you wonder why DMA needs dest and src? Because DMA (Direct Menory Access) direct memory access;
DMAEN: I won’t explain EN;
The remaining DMAxSA DMAxDA DMAxSZ are simple, they are the address of src and the address of dest and the size of the data;
The following is the relevant part of the source code, written in while (1)
/****************************************************** *********************************************/
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
PMMCTL0_H = PMMPW_H;
PMMCTL0_L &= ~SVSHE;
PMMCTL0_H = 0;
//The above is for power management, ignore it
UART_Init(); //Here you need to configure the baud rate, check bit, high and low bits of UART and other general configurations
DMACTL0 |= DMA1TSEL__UCA0TXIFG; //Select UCA0 as the DMA channel, i.e. P2.0 P2.1 multiplexing function
while(1)
{
uint8_t a[]={0x66,0x77,0x99}; //dest source data array
HWREG16(uart_info.base_addr + OFS_UCAxCTLW0) |= UCSWRST; //Turn off UCA0 and the serial port first, otherwise the following address configuration cannot be implemented
__data16_write_addr((unsigned short)&DMA1SA, (unsigned long) &a[0]); //Set the first address of array a to the source address
__data16_write_addr((unsigned short)&DMA1DA, (unsigned long)(uart_info.base_addr + OFS_UCAxTXBUF) ); //Set UCAxTXBUF (serial port buffer) as the target address
DMA1SZ = 3; //This is to transfer 3 bytes
DMA1CTL = DMADT_0 | DMADSTBYTE | DMASRCBYTE | DMASRCINCR_3 | DMADSTINCR_0 | DMAEN;
//Transfer a single byte //dest is byte // src is byte // 3 represents the source data address increases after a byte is transferred //The target address does not increase //Enable
HWREG16(uart_info.base_addr + OFS_UCAxCTLW0) &= ~(UCSWRST); //Open the serial port
while (0 == (DMA1CTL & DMAIFG)) //Wait for DMA to complete the data transfer, DMAIFG=1
{
}
for(int i=10000;i>=0;i--); //Delay, it may be sent too fast in while (1), no delay data error
};
}
|