SPI DMA Chip Select

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
KahHou
Level 1
Level 1
10 sign-ins 5 sign-ins First reply posted

Good morning, 

As a beginner, I am using a PSoC 5 LP.

I am trying to use SPI communication with DMA to send words of 2bytes.

However I have this problem of Chip Select Signal

Here are my program and my configurations : 

#include <project.h>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void DmaTxConfiguration(void);
void DmaRxConfiguration(void);

/* DMA Configuration for DMA_TX */
#define DMA_TX_BYTES_PER_BURST (2u)
#define DMA_TX_REQUEST_PER_BURST (1u)
#define DMA_TX_SRC_BASE (CYDEV_SRAM_BASE)
#define DMA_TX_DST_BASE (CYDEV_PERIPH_BASE)

/* DMA Configuration for DMA_RX */
#define DMA_RX_BYTES_PER_BURST (2u)
#define DMA_RX_REQUEST_PER_BURST (1u)
#define DMA_RX_SRC_BASE (CYDEV_PERIPH_BASE)
#define DMA_RX_DST_BASE (CYDEV_SRAM_BASE)

#define BUFFER_SIZE (18u)
#define STORE_TD_CFG_ONCMPLT (1u)

/* Variable declarations for DMA_TX*/
uint8 txChannel;
uint8 txTD;

/* Variable declarations for DMA_RX */
uint8 rxChannel;
uint8 rxTD;

uint16 txBuffer [BUFFER_SIZE] = {0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700, 0x0800, 0x0900, 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0x4000, 0x4000};

int16 rxBuffer[BUFFER_SIZE];

 

/*******************************************************************************
* Function Name: DmaTxConfiguration
********************************************************************************
* Summary:
* Configures the DMA transfer for TX direction
*
* Parameters:
* None.
*
* Return:
* None.
*
*******************************************************************************/
void DmaTxConfiguration()
{
/* Init DMA, 1 byte bursts, each burst requires a request */
txChannel = DMA_TX_DmaInitialize(DMA_TX_BYTES_PER_BURST, DMA_TX_REQUEST_PER_BURST,
HI16(DMA_TX_SRC_BASE), HI16(DMA_TX_DST_BASE));

txTD = CyDmaTdAllocate();

/* Configure this Td as follows:
* - Increment the source address, but not the destination address
*/
CyDmaTdSetConfiguration(txTD, (BUFFER_SIZE*2), txTD, TD_INC_SRC_ADR);

/* From the memory to the SPIM */
CyDmaTdSetAddress(txTD, LO16((uint32)txBuffer), LO16((uint32) SPIM_BSPIM_sR16_Dp_u0__16BIT_F0_REG));

/* Associate the TD with the channel */
CyDmaChSetInitialTd(txChannel, txTD);
}


/*******************************************************************************
* Function Name: DmaRxConfiguration
********************************************************************************
* Summary:
* Configures the DMA transfer for RX direction
*
* Parameters:
* None.
*
* Return:
* None.
*
*******************************************************************************/
void DmaRxConfiguration()
{
/* Init DMA, 1 byte bursts, each burst requires a request */
rxChannel = DMA_RX_DmaInitialize(DMA_RX_BYTES_PER_BURST, DMA_RX_REQUEST_PER_BURST,
HI16(DMA_RX_SRC_BASE), HI16(DMA_RX_DST_BASE));

rxTD = CyDmaTdAllocate();

/* Configure this Td as follows:
* - Increment the destination address, but not the source address
*/
CyDmaTdSetConfiguration(rxTD, (BUFFER_SIZE*2), rxTD, TD_INC_DST_ADR);

/* From the SPIM to the memory */
CyDmaTdSetAddress(rxTD, LO16((uint32)SPIM_BSPIM_sR16_Dp_u0__F1_REG), LO16((uint32)rxBuffer));

/* Associate the TD with the channel */
CyDmaChSetInitialTd(rxChannel, rxTD);
}

 

 

KahHou_0-1621599828203.pngKahHou_1-1621599847171.pngKahHou_2-1621599863349.png

 

KahHou_3-1621599877597.png

 

However, my Chip Select signal doesn't seem to agree with what I want it to do.

 

KahHou_4-1621600010106.png

 

As what I have understood, #define DMA_TX_BYTES_PER_BURST (2u), it should send 2 bytes and I should have a chip select pulse, however, it sends 4bytes and it gives me a pulse on chip select .

Sorry if I have misunderstood this, but anyone has an idea what can I do ?

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

KahHou,

I'll try to help if I can.

You set your DMA_TX and DMA_RX to 'level'.  Is there a reason for this Hardware Request type?

Setting to 'level' can be tricky.  Normally you would chose 'Derived' or "Rising Edge'.  Depending on the signal that starts the DMA, a pronged signal with 'level' as the request type can cause multiple transfers on the same signal.  This is great if that's what you're trying to do.

In order for I or others to further help here, can you attached an archive of your project to this thread?

You're missing potential critical information to root cause your issue.  With your project, we can potentially reproduce the issue and more quickly provide a root cause and solution.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
2 Replies