SPI Library: No apparent parameters for Master Sync Config

Post your requests and ideas on the future development of mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
steve42lawson
Posts: 183
Joined: 06 Mar 2008 17:35
Location: St. George, UT
Contact:

SPI Library: No apparent parameters for Master Sync Config

#1 Post by steve42lawson » 07 Nov 2017 23:00

I was trying to control an AD5292 Digital Potentiometer using a PIC24F32KA302's SPI1 module. Using the following test code:

Code: Select all

#define DPOT_CMD__WRITE_RVAL 0b0001
void main() {
    TRISB   = 0x41b4;
    SPI1_Init();
    SPI1_Init_Advanced(_SPI_MASTER, _SPI_16_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_1, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_ACTIVE_2_IDLE);

    while(1)
    {
        SPI1_Write((DPOT_CMD__WRITE_RVAL << 10) | (0x3ff & 0b0101010101));
        Delay_us(100);
    }
My scope shows the expected data pattern and a clock signal to go with it, but NO SYNC signal. So I tried adding the following:

Code: Select all

#define DPOT_CMD__WRITE_RVAL 0b0001
unsigned int data_to_send =  0x55;
oid main() {
    TRISB  = 0x41b4;
    SPI1_Init();
    SPI1_Init_Advanced(_SPI_MASTER, _SPI_16_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_1, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_ACTIVE_2_IDLE);
    // *****************  ADDED THESE  *******************
    FRMEN_bit = 1;
    SPIFSD_bit = 0;
    SPIFPOL_bit = 0;
    SPIFE_bit = 0;
    // **************************************************

    while(1)
    {
        SPI1_Write((DPOT_CMD__WRITE_RVAL << 10) | (0x3ff & data_to_send);
        Delay_us(100);
    }
Still NO SYNC pulse! That's when I discovered that these defines (FRMEN_bit, SPIFSD_bit , etc) are only defined for SDI2 (NOT SDI1!). I even tried doing this with SPI2 and STILL NO SYNC PULSE -- so not sure why these are even defined at all!!

So, I tried the following:

Code: Select all

#define DPOT_CMD__WRITE_RVAL 0b0001
unsigned int data_to_send =  0x55;
void main() {
    TRISB   = 0x41b4; 
    SPI1_Init();
    SPI1_Init_Advanced(_SPI_MASTER, _SPI_16_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_1, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_ACTIVE_2_IDLE);
    // **********************   ADDED THIS  ************************
    SPI1CON2 = 0x8001;  // bit15: Framed SPI support enabled, etc.
    // ***********************************************************

    while(1)
    {
        SPI1_Write((DPOT_CMD__WRITE_RVAL << 10) | (0x3ff & data_to_send));
        Delay_us(100);
    }

Still NO SYNC pulse!

I had to do THIS to get Framed SDI to work on SDI1:

Code: Select all

#define DPOT_CMD__WRITE_RVAL 0b0001
unsigned int data_to_send =  0x55;
unsigned int temp;  // A place to put the SDI read that, apparently, is necessary to make this work.
void main() {
    TRISB   = 0x41b4;
    SPI1CON1 = 0x04bb;
    SPI1CON2 = 0xa001;    // Framing enabled, Sync pulse as Master, Sync pulse Polarity = 1,
    SPI1STAT = 0xa000;     // Enable SPI1
    
    while(1)
    {
        SPI1BUF = (DPOT_CMD__WRITE_RVAL << 10) | (0x3ff & data_to_send );
         while (SPI1STAT & 0x0002)
        {
            ;
        }
        // Some sort of delay need here, because all this detects is when the shift register is loaded from the 
        // the SPI Buffer.  Or, there is an interrupt [SPI1IE: SPI1 Transfer Complete] that looks like it might do the trick-- but I didn't try it.
        // Also, instead of reading the SPI1BUF, it looks like all I really had to do was Clear the SPIROV bit.
        temp = SPI1BUF;
    }
}
In other words, I, basically, had to implement it myself (so often this is the case -- the library functions provided with the MikroC compiler are so minimally implemented, that they, usually, don't serve my needs and I have to do it myself -- thus leading me to wonder, what have I gained by buying this thing?!)

SOOOOO... my wish is that you guys do the following:

1. Change the FRMEN_bit, SPIFSD_bit , etc defines so they have a SDI1 and SDI2 context in cases where the PIC has two (or more) SID modules. Something like FRMEN1_bit & FRMEN2_bit.
2. Add Framed SDI capability to the SPIx_Init_Advanced() function, or add a separate function for setting this up.
Humility is the lack of the desire to impress, not the lack of being impressive.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: SPI Library: No apparent parameters for Master Sync Conf

#2 Post by filip » 10 Nov 2017 18:06

Hi,
Still NO SYNC pulse! That's when I discovered that these defines (FRMEN_bit, SPIFSD_bit , etc) are only defined for SDI2 (NOT SDI1!). I even tried doing this with SPI2 and STILL NO SYNC PULSE -- so not sure why these are even defined at all!!
As far I can see, these bits are defined in the definition file of this MCU, please have a look at this code snipped from it :

Code: Select all

    // SPI1CON2 bits
    sbit  FRMEN_bit at SPI1CON2.B15;
    sbit  FRMEN_SPI1CON2_bit at SPI1CON2.B15;
    
    sbit  SPIFSD_bit at SPI1CON2.B14;
    sbit  SPIFSD_SPI1CON2_bit at SPI1CON2.B14;

    sbit  SPIFPOL_bit at SPI1CON2.B13;
    sbit  SPIFPOL_SPI1CON2_bit at SPI1CON2.B13;

    sbit  SPIFE_bit at SPI1CON2.B1;
    sbit  SPIFE_SPI1CON2_bit at SPI1CON2.B1;

    sbit  SPIBEN_bit at SPI1CON2.B0;
    sbit  SPIBEN_SPI1CON2_bit at SPI1CON2.B0;

    // SPI2CON2 bits
    sbit  FRMEN_SPI2CON2_bit at SPI2CON2.B15;
    sbit  SPIFSD_SPI2CON2_bit at SPI2CON2.B14;
    sbit  SPIFPOL_SPI2CON2_bit at SPI2CON2.B13;
    sbit  SPIFE_SPI2CON2_bit at SPI2CON2.B1;
    sbit  SPIBEN_SPI2CON2_bit at SPI2CON2.B0;
In other words, I, basically, had to implement it myself (so often this is the case -- the library functions provided with the MikroC compiler are so minimally implemented, that they, usually, don't serve my needs and I have to do it myself -- thus leading me to wonder, what have I gained by buying this thing?!)
There is no need for implementing this when it is already defined.
Please, if you don't find something (in this case a bit definition), maybe you could write to us first for help, there is no need for any aggravation here.
SOOOOO... my wish is that you guys do the following:

1. Change the FRMEN_bit, SPIFSD_bit , etc defines so they have a SDI1 and SDI2 context in cases where the PIC has two (or more) SID modules. Something like FRMEN1_bit & FRMEN2_bit.
2. Add Framed SDI capability to the SPIx_Init_Advanced() function, or add a separate function for setting this up.
You are right about adding the Framed SDI capability, I will report this to our developers.

Regards,
Filip.

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 Wish List”