SPI initalization on PIC24FJ1024GA610/GB610 family

General discussion on mikroPascal PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
erkileitaru
Posts: 28
Joined: 29 Dec 2009 08:53

SPI initalization on PIC24FJ1024GA610/GB610 family

#1 Post by erkileitaru » 20 Aug 2017 15:56

I think there is error in SPIx_Init_Advanced function. It wants values for primary and secondary prescalers, but this chip has baud rate register and not those prescalers. Therefore SPI library can't be used on that chip.

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: SPI initalization on PIC24FJ1024GA610/GB610 family

#2 Post by lana.arsic » 21 Aug 2017 13:37

Hi,

Definitions can be different than the ones provided in Help file,
I suggest you to use Code Assistant (Ctrl + Space) when you call function.

For P24FJ1024GA610 SPIx_Init_Advanced is defined as:

Code: Select all

void SPIx_Init_Advanced(unsigned master_mode, unsigned mode16, unsigned slave_select, unsigned data_sample, unsigned clock_idle, unsigned int brgDiv, unsigned edge); 
All parameters, except brgDiv, are described in the Help menu,
as regards parameter brgDiv, it is the one which is used in the equation on page 246:

http://ww1.microchip.com/downloads/en/D ... 10074e.pdf

for calculating SPI Baud Rate.
When you use SPIx_Init() function, that parameter is equal to zero.

For P24FJ1024GA610 you can use for example:

Code: Select all

SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT,_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, 0, _SPI_ACTIVE_2_IDLE);
Kind regards,
Lana

erkileitaru
Posts: 28
Joined: 29 Dec 2009 08:53

Re: SPI initalization on PIC24FJ1024GA610/GB610 family

#3 Post by erkileitaru » 15 Oct 2017 11:50

Hi, I have another bug to report: BrgDiv does not have any effect on SPI speed

If my Fosc=8MHz, then SPI3_Init_Advanced(_SPI_MASTER, _SPI_8_BIT,_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, 10, _SPI_ACTIVE_2_IDLE); makes clock speed always around 2MHz, no matter if I put 0, 1, 10 or whatever;

To change clock speed, I have to add following commands after SPI3_Init_Advanced:

SPI3CON1L.15:=0;
SPI3BRGL:=10;
SPI3CON1L.15:=1;

It makes me wonder, what "hidden features" you have more with this MCU. There are already 3 nonconformities to the user manual in SPI library alone.

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: SPI initalization on PIC24FJ1024GA610/GB610 family

#4 Post by lana.arsic » 17 Oct 2017 16:09

Hi,

I apologize for this inconvenience,
thank you for reporting this, I have forwarded it to our developers.

Mistake was in SPI3 function (SPI1 and SPI2 were not affected), you can try to replace
existing library with library from the attachment.

The library which should be replaced can be found in the installation folder in the compiler,
for example in: c:\Users\Public\Documents\Mikroelektronika\mikroPascal PRO for dsPIC\Uses.

Kind regards,
Lana
Attachments
__Lib_SPI_1234_p24fj_gx.zip
(5.05 KiB) Downloaded 124 times

Post Reply

Return to “mikroPascal PRO for dsPIC30/33 and PIC24 General”