Hello,
I was working on a simple program to test the SCI2 and DMA modules and I ran into a couple of problems involving SCI. The code below demonstrates one of the problems. It is intended to read a fixed number of characters from the SCIRD buffer and write them to an array using DMA, where the DMA transfer is HW triggered by SCI whenever data is available to be read. The problem is that the DMA transfer never occurs, even though input characters show up on SCIRD successfully. I think either no transfer request is being sent by SCI, or DMA does not correctly respond to the request. I am using HALCoGen 04.00.00, CCS v5 and the XDS100v2 USB emulator. I am using the CCS terminal to input characters. Here is the sys_main.c file:
/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "sci.h"
#include "sys_dma.h"
/* USER CODE END */
/* USER CODE BEGIN (2) */
g_dmaCTRL ctrl;
unsigned char dest[11] = { 0 };
uint32 btc_flag = 0;
/* USER CODE END */
void main(void)
{
/* USER CODE BEGIN (3) */
_enable_IRQ();
sciInit();
dmaEnable();
/* DMA Channel 0 Control Packet Config (Reading from SCIRD) */
ctrl.SADD = (uint32)((uint8*)&(scilinREG->RD)+3); /* Read the receive buffer byte directly */
ctrl.DADD = (uint32)dest;
ctrl.CHCTRL = 0U; /* Chaining disabled */
ctrl.FRCNT = 11U;
ctrl.ELCNT = 1U;
ctrl.ELDOFFSET = 0U; /* Indexed mode disabled */
ctrl.ELSOFFSET = 0U; /* Indexed mode disabled */
ctrl.FRDOFFSET = 0U; /* Indexed mode disabled */
ctrl.FRSOFFSET = 0U; /* Indexed mode disabled */
ctrl.PORTASGN = 4U; /* Port B */
ctrl.RDSIZE = ACCESS_8_BIT; /* Read a single byte */
ctrl.WRSIZE = ACCESS_8_BIT; /* Write a single byte */
ctrl.TTYPE = FRAME_TRANSFER;
ctrl.ADDMODERD = ADDR_FIXED; /* Fixed address read */
ctrl.ADDMODEWR = ADDR_INC1; /* Post-incremented write */
ctrl.AUTOINIT = AUTOINIT_OFF;
dmaSetCtrlPacket(DMA_CH0, ctrl);
dmaReqAssign(DMA_CH0, 28U);
dmaSetChEnable(DMA_CH0, DMA_HW);
scilinREG->SETINT = (uint32)((uint32)1 << 17); /* Enable SCI DMA request */
/** Transfer start **/
while(btc_flag != 1U); /* Wait until BTC ISR sets the flag */
btc_flag = 0U;
scilinREG->CLEARINT = (uint32)((uint32)1 << 17); /* Disable SCI DMA request */
while(1);
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
void dmaGroupANotification(dmaInterrupt_t inttype, uint32 channel){
btc_flag = 1U;
}
/* USER CODE END */
I can't figure out what I may be doing wrong, because I can successfully write data to SCITD using DMA with the same method and have it printed on the terminal. The following code works without a problem, and prints "Hello world" on the terminal:
/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "sci.h"
#include "sys_dma.h"
/* USER CODE END */
/* USER CODE BEGIN (2) */
g_dmaCTRL ctrl;
unsigned char src[11] = {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};
uint32 btc_flag = 0;
/* USER CODE END */
void main(void)
{
/* USER CODE BEGIN (3) */
_enable_IRQ();
sciInit();
dmaEnable();
/* DMA Channel 0 Control Packet Config (Writing to SCITD) */
ctrl.SADD = (uint32)src;
ctrl.DADD = (uint32)((uint8*)&(scilinREG->TD)+3); /* Write on the transmit buffer byte directly */
ctrl.CHCTRL = 0U; /* Chaining disabled */
ctrl.FRCNT = 11U;
ctrl.ELCNT = 1U;
ctrl.ELDOFFSET = 0U; /* Indexed mode disabled */
ctrl.ELSOFFSET = 0U; /* Indexed mode disabled */
ctrl.FRDOFFSET = 0U; /* Indexed mode disabled */
ctrl.FRSOFFSET = 0U; /* Indexed mode disabled */
ctrl.PORTASGN = 4U; /* Port B */
ctrl.RDSIZE = ACCESS_8_BIT; /* Read a single byte */
ctrl.WRSIZE = ACCESS_8_BIT; /* Write a single byte */
ctrl.TTYPE = FRAME_TRANSFER;
ctrl.ADDMODERD = ADDR_INC1; /* Post-incremented read */
ctrl.ADDMODEWR = ADDR_FIXED; /* Fixed address write */
ctrl.AUTOINIT = AUTOINIT_OFF;
dmaSetCtrlPacket(DMA_CH0, ctrl);
dmaReqAssign(DMA_CH0, 29U);
dmaSetChEnable(DMA_CH0, DMA_HW);
scilinREG->SETINT = (uint32)((uint32)1 << 16); /* Enable SCI TX DMA request */
/** Transfer start **/
while(btc_flag != 1U); /* Wait until BTC ISR sets the flag */
btc_flag = 0U;
scilinREG->CLEARINT = (uint32)((uint32)1 << 16); /* Disable SCI TX DMA request */
while(1);
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
void dmaGroupANotification(dmaInterrupt_t inttype, uint32 channel){
btc_flag = 1U;
}
/* USER CODE END */
Attached is the CCS project, in case it is required. Any help would be much appreciated. Thanks a lot in advance.
Cagil