cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

KahHou
New Contributor

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
2 Replies
Len_CONSULTRON
Honored Contributor II

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."
0 Likes
KahHou
New Contributor

Good morning Len, 

Thank you very much , my problem of DMA_TX is solved by changing "Level" to "Derived"

Thanks for your explanations. I understand much better DMA and SPI now.

However, now I am having problem with my rxBuffer, I don't think I have received the correct data from my slave.

 

So for my SPI interrupts, I have Enable Rx Internal Interrupt and Interrupt On Rx FIFO Not Empty

and DMA_RX Hardware Request "Level"

And I think this should trigger my DMA_RX all the time, since Rx FIFO is always Not Empty, 

 

 I received this in debugger of PSoC Creator :

unknown.png

There should be at least two 0x8000 (dummy bytes) somewhere.

However, I don't receive the data that I should get :

 
 

0 Likes