Author Topic: pic24 spi module  (Read 2743 times)

0 Members and 1 Guest are viewing this topic.

Offline RendonTopic starter

  • Newbie
  • Posts: 9
pic24 spi module
« on: October 14, 2014, 05:59:25 pm »
I am using a pic24FG128GA006 and can't seem to transmit data on the spi module. I have set the registers up as per the datasheet, but no joy. The module is enabled. It is set to master. The clock and data out lines are configured as outputs.  I load data in the SPIBUF register and nothing happens. I am happy to post my code if need be but I wondered if there is anything I should know? Any insight would greatly be appreciated. I am new to PIC24 (and to SPI). Thanks :-)
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: pic24 spi module
« Reply #1 on: October 14, 2014, 07:46:33 pm »
Quote
I wondered if there is anything I should know?

Yeah: help others help you.

You are looking for help so make it as easy as possible for others to help you.
================================
https://dannyelectronics.wordpress.com/
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1638
  • Country: nl
Re: pic24 spi module
« Reply #2 on: October 14, 2014, 08:13:28 pm »
In theory the SPI module should be rather easy and straight forward if you're not going to use any advanced features.

Make sure (SPIxCON1):
You're not using both primary & secondary prescale 1:1. For example, set one to 1:2 or 1:4, and the other to 1:1 (if you really need the high clock speed).
Enable master mode (bit 5 = 1)
Select your clock settings (bit 6 and 8 ). You should see some clocks I think, but if they are set wrong you may lose your first or last bit.
I would set data sampling at middle if your clock speed allows it
Make sure you enable the SDO and SCK.

SPIxCON2 is all for FIFO and SPI framing. Set it to 0 if you don't use it Make sure to read the errata if you do want to use that, some early PIC24 parts had some horrible FIFO bugs.

When transmitting just poll the SPIxSTAT.SPIRBF bit until it goes high, then the transfer should be done.

SPIxSTAT.SPIEN (bit 15) should be set to 1 to enable the module. Make sure to reset the module before configuring it, you can't first enable the module and then change registers. In my projects I reset all registers to 0 (CON1, CON2, STAT), write my settings, and then enable the module.


That's about it as far as I can see. It seems like the PIC24FJ128GA006 does not have PPS, so that's one less module to worry about.

If you do have all of this, then feel free to post your code. Otherwise we can only guess (like this post is all about).
« Last Edit: October 14, 2014, 08:15:40 pm by hans »
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13745
  • Country: gb
    • Mike's Electric Stuff
Re: pic24 spi module
« Reply #3 on: October 14, 2014, 08:41:25 pm »
Something I think the datasheet mentions that I've not checked to see if it matters is to set up all the registers with the ON bit in SPICON1 clear,  then set the ON bit as a final action.
 
And of course map the pins on parts with remappable IOs
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline mazurov

  • Frequent Contributor
  • **
  • Posts: 524
  • Country: us
Re: pic24 spi module
« Reply #4 on: October 15, 2014, 01:03:04 am »
Where did you get this part? Microchip isn't aware of it. If you meant FJ then how did you test? If you don't have a scope connect MISO to MOSI and you should be able to read back SPIBUF :-). If you're testing with another device make sure SPI modes are compatible on both.
With sufficient thrust, pigs fly just fine - RFC1925
 

Offline RendonTopic starter

  • Newbie
  • Posts: 9
Re: pic24 spi module
« Reply #5 on: October 16, 2014, 07:56:06 pm »
Thank you Hans! Problem solved :-)

The solution was to set the enable bit last. Lesson learned. Many thanks.

mazurov, it's a PIC24FJ, not FG. Typo on my part.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf