Page 1 of 1

SPI initalization on PIC24FJ1024GA610/GB610 family

Posted: 20 Aug 2017 15:56
by erkileitaru
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.

Re: SPI initalization on PIC24FJ1024GA610/GB610 family

Posted: 21 Aug 2017 13:37
by lana.arsic
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

Re: SPI initalization on PIC24FJ1024GA610/GB610 family

Posted: 15 Oct 2017 11:50
by erkileitaru
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.

Re: SPI initalization on PIC24FJ1024GA610/GB610 family

Posted: 17 Oct 2017 16:09
by lana.arsic
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