PIC32MZ2048 SPI Uart i2c speed

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

stefan.erni
Posts: 553
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 173 times
Been thanked: 160 times
Contact:

PIC32MZ2048 SPI Uart i2c speed

Postby stefan.erni » Tue Nov 21, 2017 4:11 pm

Hi Ben

First the good news.

IRQ:
The Irq is working nice with FC7. Just choose rollover and prescaler. And the IRQ frequenz is showing at the screen.
With the osciloscope controlled. It's perfect 2.000kHz.

Delay:
The same with the delay. Choose 1 Sec and its one second in the scope......

I2c:
Now the not so good side...
I choosed 1Mega but the result is 532kHz

SPI:
I choosed maximal (div2) and expect 50Mhz but the result is 3.2 MHz

UART
I choosed 1200Bd (Bitlength 833uSec and expect 2x833uSec=1.66mSec but the result is 3.33mSec
for a control I connected the uart to a computer. For a comunication I have to reduce the speed in the computer.

All the measurements results are in the PDF.

Can You help me to fix this few problems?


IRQ.PNG
IRQ.PNG (8.57 KiB) Viewed 2867 times

IRQ_2kHz 0.png
IRQ_2kHz 0.png (16.3 KiB) Viewed 2867 times



result.pdf
(333.71 KiB) Downloaded 69 times
These users thanked the author stefan.erni for the post:
Benj (Thu Dec 07, 2017 9:19 pm)
Rating: 5%
 

User avatar
Benj
Matrix Staff
Posts: 14660
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4651 times
Been thanked: 4268 times
Contact:

Re: PIC32MZ2048 SPI Uart i2c speed

Postby Benj » Thu Dec 07, 2017 9:21 pm

Hello,

Sorry for the delay and thanks for letting us know.

Is it possible for you to attach the Flowcode project file so we can look at things like the config etc. I'll investigate to see if there are any additional hidden prescalers that could be effecting the comms peripherals speed.
These users thanked the author Benj for the post:
stefan.erni (Fri Dec 08, 2017 9:21 am)
Rating: 5%
 

stefan.erni
Posts: 553
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 173 times
Been thanked: 160 times
Contact:

Re: PIC32MZ2048 SPI Uart i2c speed

Postby stefan.erni » Fri Dec 08, 2017 9:20 am

Hi Ben

Thank you for the support.

Here the Flowcode project file and a plan which pin I used for the scope. I used PICkit3 as programmer.

Flowcode_Emg_2018_icsp1_speedtest_ma1.fcfx
(17.77 KiB) Downloaded 81 times



Wifire.png
Wifire.png (341.44 KiB) Viewed 2789 times

User avatar
Benj
Matrix Staff
Posts: 14660
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4651 times
Been thanked: 4268 times
Contact:

Re: PIC32MZ2048 SPI Uart i2c speed

Postby Benj » Thu Dec 14, 2017 11:39 am

Hello

The SPI peripheral has a bit which chooses either the PBCLK2 or the REFCLKO1 as the clock source. The PBCLK2 is the default setting. Currently I'm not sure how this clock is adjusted. Looking into it now.

You can try switching to the REFCLKO1 by using the following C code after initialising the SPI component.

Code: Select all

SPI1CONbits.MCLKSEL = 1;


The I2C Baud calculation looks a bit over complicated so this probably needs investigating too.

This is the PIC32 version.

Code: Select all

#define MX_I2C_HW_BAUD   ((((1.0f/ (2.0f * MX_I2C_BAUD_X)) - (0.104f/1000000.0f)) * MX_CLK_SPEED) - 2 )


The is the PIC16 version - note no floating point calculations.

Code: Select all

#define MX_I2C_HW_BAUD   ((MX_CLK_SPEED / MX_CLKS_PER_INST) / MX_I2C_BAUD_X) - 2

stefan.erni
Posts: 553
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 173 times
Been thanked: 160 times
Contact:

Re: PIC32MZ2048 SPI Uart i2c speed

Postby stefan.erni » Thu Dec 14, 2017 4:52 pm

Hi Ben

I tried to set the bit in SPI2CON but then is the hardware spi not working and the software is not bether.
I found an another problem in FC7.
startet the board in hardware spi2 and it's run on 50Mhz. Perfect.
Ichanched to software, the speed goes down to 3Mhz.
go back to hardware and it's slow too.
If I toggle the hardware/software without compiele it's slow 3Mhz. (Both hard and soft spi)
The good thing is.... if I go change to hardware 1 and back to hardware2 it's 50Mhz again.
I trie now the I2c....

But do you have a good idea for the UART?

stefan.erni
Posts: 553
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 173 times
Been thanked: 160 times
Contact:

Re: PIC32MZ2048 SPI Uart i2c speed

Postby stefan.erni » Thu May 31, 2018 9:05 am

Hi Ben


@UART
@I choosed 1200Bd (Bitlength 833uSec and expect 2x833uSec=1.66mSec but the result is 3.33mSec
@for a control I connected the uart to a computer. For a comunication I have to reduce the speed in the computer.

I have still the problem with the speed of the uart. It's factor 2 wrong.
And is it possible to add some higher speed in the menue?
230400
460800
921600

regards

Stefan

User avatar
Benj
Matrix Staff
Posts: 14660
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4651 times
Been thanked: 4268 times
Contact:

Re: PIC32MZ2048 SPI Uart i2c speed

Postby Benj » Wed Jun 06, 2018 5:14 pm

Hi Stefan,

I've answered you here in a move to try and fix the speed problems on PIC32.
viewtopic.php?f=78&t=20139#p88753

The datasheets don't make things easy and a fix for one device seems to cause problems on other device in the same family. Anyway we should be able to get to the bottom of things if we take it a device at a time and focus on what's not working.