我想要使用DMA推送spi数据,但是每次调用DMA_startTransfer(DMA_CHANNEL_0);函数都不会有spi数据发出,如果使EUSCI_A_SPI_transmitData(EUSCI_A0_BASE,_74hc595_send_buf[0]);发送spi数据后,能进入dma中断。初始化配置代码如下,请专家批评指正,感激不尽!
1、dma初始化函数
void dma_init(void)
{
uint8_t *p;
//Initialize and Setup DMA Channel 0
p = _74hc595_send_buf;
DMA_initParam param = {0};
param.channelSelect = DMA_CHANNEL_0;
param.transferModeSelect = DMA_TRANSFER_BLOCK; //块传输
param.transferSize = 18;
param.triggerSourceSelect = DMA_TRIGGERSOURCE_15;
param.transferUnitSelect = DMA_SIZE_SRCBYTE_DSTBYTE; //字节到字节
param.triggerTypeSelect = DMA_TRIGGER_RISINGEDGE;
DMA_init(¶m);
DMA_setSrcAddress(DMA_CHANNEL_0,
(uint32_t)p,
DMA_DIRECTION_INCREMENT); //地址递增
DMA_setDstAddress(DMA_CHANNEL_0,
(EUSCI_A0_BASE + OFS_UCAxTXBUF),
DMA_DIRECTION_UNCHANGED); //地址不变
//clear channel 0 flg
DMA_clearInterrupt(DMA_CHANNEL_0);
//enble channel 0 interrupt
DMA_enableInterrupt(DMA_CHANNEL_0);
//Enable transfers on DMA channel 0
DMA_enableTransfers(DMA_CHANNEL_0);
}
2、spi初始化函数:
void SPI_A0_init(void)
{
// 锁存脚设置
_74HC595_SPI_RCLK_INIT;
//Set all PA pins HI
GPIO_setOutputHighOnPin(
GPIO_PORT_P1,
GPIO_PIN5
);
GPIO_setOutputHighOnPin(
GPIO_PORT_P2,
GPIO_PIN0 );
/*
* Select Port 1
* Set Pin 5 to input Secondary Module Function, (UCA0CLK).
*/
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P1,
GPIO_PIN5,
GPIO_SECONDARY_MODULE_FUNCTION
);
// Configure Pins for UCA0TXD/UCA0SIMO, UCA0RXD/UCA0SOMI
//Set P2.0, P2.1 as Secondary Module Function Input.
/*
* Select Port 2
* Set Pin 0, 1 to input Secondary Module Function, (UCA0TXD/UCA0SIMO, UCA0RXD/UCA0SOMI).
*/
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P2,
GPIO_PIN0,
GPIO_SECONDARY_MODULE_FUNCTION
); //Initialize Master
EUSCI_A_SPI_initMasterParam param = {0};
param.selectClockSource = EUSCI_A_SPI_CLOCKSOURCE_SMCLK;
param.clockSourceFrequency = CS_getSMCLK();
param.desiredSpiClock = 5000000;
param.msbFirst = EUSCI_A_SPI_LSB_FIRST;
param.clockPhase = EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT;
param.clockPolarity = EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW;
param.spiMode = EUSCI_A_SPI_3PIN;
EUSCI_A_SPI_initMaster(EUSCI_A0_BASE, ¶m);
//Enable SPI module
EUSCI_A_SPI_enable(EUSCI_A0_BASE);
//Clear receive interrupt flag
EUSCI_A_SPI_clearInterrupt(EUSCI_A0_BASE,
EUSCI_A_SPI_RECEIVE_INTERRUPT
);
//Wait for slave to initialize
__delay_cycles(100);
}
Seven Han:
http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/567993
可参考以上帖子中的讨论