• AVR Freaks

dsPIC33 SPI problem or deficiency

Author
mdbayehp
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2009/03/08 22:41:02
  • Location: 0
  • Status: offline
2009/03/08 23:08:50 (permalink)
0

dsPIC33 SPI problem or deficiency

Hi y'all

Please bear with me as I'm new to SPI and the Microchip products. I'm trying to use the SPI interface of dsPIC33FJ256 demo board with the explorer16. I wanted to interface to the MCP4922 DAC from Microchip. However, I'm having a problem controlling the SSx pin from the dsPIC. When I do write to the DAC, I do see the clock and data out signals ok. But the SSx pin stays silent. As far as I can see on the SPI datasheet of the dsPIC, the SSx pin is used only in slave mode or in master frame mode. The DAC does need to have the CS input activated to accept new data. I don't want to use an I/O port to bit bang the CS input of the DAC as I want to update the DAC @ over 1MHz using the DMA to do a burst transfer.

Here is some code to do a signle dac update without using the DMA. This is a simple test without involving interrupts.

void DAC_Init( void )
{
    // Configure SPI1 for dac control
    SPI1STAT    = 0;    // disable SPI1
    SPI1CON1bits.DISSCK = 0; //Internal Serial Clock is Enabled.
    SPI1CON1bits.DISSDO = 0; //SDOx pin is controlled by the module.
    SPI1CON1bits.MODE16    = 1;    // select 16bit operation
    SPI1CON1bits.SMP = 0;    //Input Data is sampled at the middle of data output time.
    SPI1CON1bits.CKE = 1;    //Serial output data changes on transition from
    SPI1CON1bits.CKP = 0;    //Idle state for clock is a low level;
    SPI1CON1bits.SSEN = 0;    //disable slave select bit
    SPI1CON1bits.MSTEN  = 1;    // select master mode
    SPI1CON1bits.PPRE    = 2;    // select 4:1 primary prescaler
    SPI1CON1bits.SPRE    = 0;    // selelct 8:1 secondary prescaler

}

Writing to the DAC

    SPI1STATbits.SPIEN = 1;   // enable SPI1
    SPI1BUF = out;                //

What am I missing? Why can't the silly SPI have the SSx act as CS output?

Separate topic assuming I get the above resolved--
Ultimately I want to use the DMA in continuous ping pong operation with HALF data transfer interrupt mode. The question is when I get the interrupt for bufferA, can I change the start address offset for bufferB without disrupting the DMA operation and vice versa?

Please help. I appreciate any input.
Thanx.
#1

5 Replies Related Threads

    sbs136
    Senior Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2007/08/16 01:35:49
    • Location: 0
    • Status: offline
    RE: dsPIC33 SPI problem or deficiency 2009/03/09 00:39:03 (permalink)
    0
    For one thing, the SS pin does not act on its own. The pin has to be either driven high or low by the application.
     
    Next, if the built in functions provided with the C30 compiler is used to place the result buffers in the DMA space, the user has no control over the address where the buffer would be located. It is also strongly recommended not to modify the control and configuration bits of the peripherals when the peripheral is enabled.
    #2
    mdbayehp
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2009/03/08 22:41:02
    • Location: 0
    • Status: offline
    RE: dsPIC33 SPI problem or deficiency 2009/03/09 00:57:22 (permalink)
    0
    Thanks for the response. I thought the SSx pin could be configured once at least per session. So, what can I do to send a burst transmission using DMA support without having to bit-bang an I/O line?
    #3
    sbs136
    Senior Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2007/08/16 01:35:49
    • Location: 0
    • Status: offline
    RE: dsPIC33 SPI problem or deficiency 2009/03/12 19:29:25 (permalink)
    0
    The SSx line can be driven low just before enabling the SPI transmission. Once you determine the completion of transmission, the SSx line can be driven high by the user in the code. 
    #4
    mdbayehp
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2009/03/08 22:41:02
    • Location: 0
    • Status: offline
    RE: dsPIC33 SPI problem or deficiency 2009/03/13 10:10:01 (permalink)
    0
    I understand the SSx line has to be activated before the transfer and deactivated after. If the user application were to do this, it would make the DMA completely useless for the SPI operation if before and after each data transfer the user app has to be involved. I've seen an example project that uses DMA but for data transfer but between two dsPIC parts that operated without the SSx line being used. As far as I know, most, if not all, SPI devices need the CS input to be stroked.

    I'm still at a loss how the DMA can be used to transfer a bunch of data to an SPI device that requires the CS input to be activated.
    #5
    bosco
    Super Member
    • Total Posts : 2119
    • Reward points : 0
    • Joined: 2004/07/24 10:17:53
    • Location: Idaho
    • Status: offline
    RE: dsPIC33 SPI problem or deficiency 2009/03/13 15:39:23 (permalink)
    0

    ORIGINAL: mdbayehp

    I understand the SSx line has to be activated before the transfer and deactivated after. If the user application were to do this, it would make the DMA completely useless for the SPI operation if before and after each data transfer the user app has to be involved. I've seen an example project that uses DMA but for data transfer but between two dsPIC parts that operated without the SSx line being used. As far as I know, most, if not all, SPI devices need the CS input to be stroked.

    I'm still at a loss how the DMA can be used to transfer a bunch of data to an SPI device that requires the CS input to be activated.


    The caller selects the device and initiates the DMA. When the DMA completes, it generates an interrupt. The ISR can deselect the device.
    SPI is flexable, many devices do not need to be selected/deselected for each transaction. Many can be selected and just left selected (until some error condition or such).
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5