Author Topic: PIC24 spi SS pin  (Read 2460 times)

0 Members and 1 Guest are viewing this topic.

Offline RendonTopic starter

  • Newbie
  • Posts: 9
PIC24 spi SS pin
« on: October 29, 2014, 07:51:40 pm »
Hi guys,

I posted previously when I was trying to get the PIC24 spi module to work. (The device is an FJ128GA006).

My issue now is driving the SS pin low. I am addressing the Microchip MCP4921 DAC, so communication is 1-way and I'm operating the SPI module in master mode.

At the moment, I am driving the SS pin low by instruction before calling my SPI function. I then run a "for-loop" before setting the SS pin high again - by instruction.

Surely, the SPI module should take care of this? Me confused.

My initialization code is as follows:

Any insight will be appreciated.

Thanks.

void spiInit()
{
   SPI2BUF = 0;
    SPI2CON1 = 0;
    SPI2CON2 = 0;
    SPI2STAT = 0;
   
    SPI2STATbits.SPIROV = 0;  // clear overflow bit

    SPI2CON1bits.MODE16 = 1; // configure words as 16-bit
    SPI2CON1bits.MSTEN = 1;  // set as master

    SPI2CON1bits.CKP = 0;    // set clock idle state
    SPI2CON1bits.CKE = 0;
   
    SPI2CON1bits.DISSCK = 0; // enable internal clock
    SPI2CON1bits.SPRE = 4;   // configure secondary clock prescaler
    SPI2CON1bits.PPRE = 1;  // configure primary clock prescaler
    SPI2CON1bits.SSEN = 1;
    SPI2STATbits.SPIEN = 1;   // enable spi module
}
 

Offline gxti

  • Frequent Contributor
  • **
  • Posts: 507
  • Country: us
Re: PIC24 spi SS pin
« Reply #1 on: October 29, 2014, 11:46:25 pm »
Does it work? If so, what do you feel is not correct about it?

From my vague recollection, PIC SPI peripherals can drive SS in a "framed mode" where it goes low at the start of each byte and high at the end. That's not standard SPI, but it is something where hardware support would be necessary. For basic SPI in master mode there's no reason why you'd need anything other than a GPIO. Of course in slave mode SS needs to be used by hardware in order to tristate the line quickly.
 

Offline mazurov

  • Frequent Contributor
  • **
  • Posts: 524
  • Country: us
Re: PIC24 spi SS pin
« Reply #2 on: October 30, 2014, 12:37:29 am »
What exactly would you like SPI module to do with SS (in master mode)? Assert/deassert before/after sending a byte? What about 16-bit transfers? Or 32? Or 65 bytes long? How about multiple slaves?

This is why there is no SS automation in master mode.
 
With sufficient thrust, pigs fly just fine - RFC1925
 

Offline RendonTopic starter

  • Newbie
  • Posts: 9
Re: PIC24 spi SS pin
« Reply #3 on: October 30, 2014, 05:29:44 am »
In other words, it is not possible to automate the SS line?

That's what I wanted to know.

The purpose of my post is to understand the SPI capabilities better so that I may hold reasonable expectations.

Thanks for your insight.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf