Quantcast
Channel: Infineon Forums
Viewing all articles
Browse latest Browse all 9892

SPI to Memory transfer (PGDMA)

$
0
0
Hi,

I'm trying to read the input from an SPI interface trough GPDMA to the memory of an XMC4800.

In detail:
With a high PWM interrupt frequency (PWM > 750kHz) I'm sampling the SPI interface.
On every interrupt when the frame length of the SPI input is reached (18bit), I want to shift the SPI FIFO to the memory over the GPDMA.

In the attachment file there are some details about the protocol:
Channel 0: PWM Interrupt pin --> ADC starts convertsation at high edge
Channel 1: MOSI
Channel 2: CLK (about 72MHz)
Channel 3; MISO --> Data from ADC 18bit
Attachment 3033

How do I achieve this?
Some GPDMA example for Dave 4 (peripheral to peripheral , memory to peripheral and vice versa) would help alot.

Code at the moment without PGDMA:
Code:

#include <DAVE.h>                //Declarations from DAVE Code Generation (includes SFR declaration)
#include <stdio.h>

uint16_t j = 0;
uint16_t data[2048];
uinbt32_t dataArray[1024];
bool test = false;

void compare_match_handler(void)
{
        //empty = (uint16_t)SPI_MASTER_0.channel->OUTR;
        //empty = (uint32_t)SPI_MASTER_0.channel->OUTR;

        //SPI_MASTER_0.channel->IN[0] = 0xFFFF; // 32 Bit
        //SPI_MASTER_0.channel->IN[0] = 0xFFFF;
        SPI_MASTER_0.channel->IN[0] = 0x3FF; // 10 Bit --> to get all 18 bits correct
        SPI_MASTER_0.channel->IN[0] = 0x3FF;
        //SPI_MASTER_0.channel->IN[0] = 0x1FF; // 9 Bit
        //SPI_MASTER_0.channel->IN[0] = 0x1FF;

        while(XMC_USIC_CH_RXFIFO_GetLevel(SPI_MASTER_0.channel) < 2);

        data[j++] = (uint16_t)SPI_MASTER_0.channel->OUTR;
        data[j++] = (uint16_t)SPI_MASTER_0.channel->OUTR;
 }


int main(void)
{
        DAVE_STATUS_t status;
        status = DAVE_Init();          /* Initialization of DAVE APPs  */

        if(status != DAVE_STATUS_SUCCESS)
        {
                /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
                XMC_DEBUG("DAVE APPs initialization failed\n");

                while(1U)
                {
                }
        }
        PWM_Start(&PWM_0);

        /* Placeholder for user application code. The while loop below can be replaced with user application code. */
        while(1U)
        {
                if(j > 1024 && test == fale)
                {
                        PWM_Stop(&PWM_0);
                       
                        // Get 18 bit ADC values
                        for(uint32_t i = 0; i < sizeof(data); i += 2)
                        {
                                //dataArray[i] = (uint32_t)((data[i] << 17) | (data[i + 1] << 7));
                                data[i] &= ~(1 << 9);
                                dataArray[i] = (uint32_t)((data[i] << 10) | (data[i + 1] << 1));
                        }
                       
                        test = true;
                }
        }
}

Thanks
Patrick
?????

Viewing all articles
Browse latest Browse all 9892

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>