CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Help with DMA in PIC18f26k42

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pbraida



Joined: 02 Feb 2011
Posts: 14

View user's profile Send private message

Help with DMA in PIC18f26k42
PostPosted: Thu May 09, 2019 6:14 am     Reply with quote

Hi all,

My compiler version is: 5.085.

Pic is 18f26k42.

The hardware works fine.

I am try to use dma with a ram buffer and spi.
Code:
char buffer_rx[3700];

If i use :
Code:

for(i=1;i<contador;i++) {
           
spi_write(false,buffer_rx[i]);
             
}

this work fine.

But if i use dma code only the first 3 bytes are sent.

The test code only put 3700 bytes in a array and try to send this with dma to spi.
Code:
setup_dma(1,DMA_TRIGGER_NONE,DMA_TRIGGER_NONE);

I use this because the software trigger the dma.
Code:
dma_start(1,DMA_SOURCE_ADDR_IS_SFR_GPR|DMA_INC_SOURCE_ADDR|DMA_DEST_ADDR_UNCHANGED|DMA_SW_TRIGGER_STARTS_XFER|DMA_START_NOW,getenv("SFR:SPI1TXB"),&buffer_rx[0],contador-1,contador-1);

The idea is to transfer all data in the buffer to spi when this is done.

The fuses setup are:

I use restart_wdt in the code.

Code:
#include <18F26K42.h>
#device ADC=16

#FUSES WDT                      //Watch Dog Timer
#FUSES WDT512                   //Watch Dog Timer uses 1:512 Postscale
#FUSES RSTOSC_EXT               //On Power-up clock running from External Oscillator
#FUSES PRLOCK1WAY               //PRLOCKED bit can be cleared and set only once
#FUSES CKS                      //Clock Switching Enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPUT                    //No Power Up Timer
#FUSES MVECEN                   //Vector tables used for interrupts
#FUSES IVT1WAY                  //IVTLOCKED bit can be cleared and set only once
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV24                   //Brownout reset at 2.4V
#FUSES ZCDDIS                   //Zero-cross detect circuit is disabled at POR
#FUSES PPS1WAY                  //Allows only one reconfiguration of peripheral pins
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES WDTSW                    //Watch Dog Timer Postscale settable in software
#FUSES WDTWIN_SW                //Watchdog Window is settable in software
#FUSES WDTCLK_SW                //WDT clock source settable in software
#FUSES BBSIZ512                 //Boot block size 512 bytes
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)

#use delay(internal=64MHz,restart_wdt)

Thanks for any help.

Pedro.

ps(sorry for bad english).
Ttelmah



Joined: 11 Mar 2010
Posts: 14617

View user's profile Send private message

PostPosted: Thu May 09, 2019 8:21 am     Reply with quote

Your transfer needs to be triggered by SPI1. It is the interrupt from this
that says it can take another byte. Currently it is 'burst transmitting' all the
bytes to the SPI, before the first one is sent, so all that ends up being sent is
the first byte, then the two that are accepted by the FIFO.
Triggering and starting are different things. You still start using software
(in the second command), but each transfer is 'triggered' by the SPI.
pbraida



Joined: 02 Feb 2011
Posts: 14

View user's profile Send private message

Help with DMA in PIC18f26k42(solved)
PostPosted: Thu May 09, 2019 9:38 am     Reply with quote

Thanks Ttelmah for your tip.

The correct commands are:
Code:
setup_dma(1,DMA_TRIGGER_SPI1TX,DMA_TRIGGER_NONE);

dma_start(1,DMA_SOURCE_ADDR_IS_SFR_GPR|DMA_INC_SOURCE_ADDR|DMA_DEST_ADDR_UNCHANGED|DMA_HW_TRIGGER_STARTS_XFER|0x01,getenv("SFR:SPI1TXB"),&leds,1,n_leds*3);

This is working perfect now.

Thanks a lot.

Pedro
Ttelmah



Joined: 11 Mar 2010
Posts: 14617

View user's profile Send private message

PostPosted: Thu May 09, 2019 9:57 am     Reply with quote

Well done. Smile

It was the three bytes that was the 'clue'....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group