Author Topic: SPI configs increases current absorption of 70mA  (Read 12744 times)

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
SPI configs increases current absorption of 70mA
« on: August 18, 2020, 09:13:48 PM »
Hi,
I'm programming a KL03. My code has PWM, UART and a couple of interrupts. It is up and running and it only absorbs 2-3mA.
When I configure the SPI the absorbed current jumps to 75-80mA. Is this normal? Can I somehow reduce it? Even configuring and deconfiguring the SPI interface would be an acceptable solution since I use it rarely.

This is my config, just regular SPI:

Code: [Select]
#define INITIALISE_SPI_SD_INTERFACE()  POWER_UP(4, SIM_SCGC4_SPI0); \
                        _CONFIG_PERIPHERAL(B, 0, PB_0_SPI0_SCK); \
_CONFIG_PERIPHERAL(A, 7, (PA_7_SPI0_MOSI | PORT_SRE_FAST | PORT_DSE_HIGH)); \
_CONFIG_PERIPHERAL(A, 6, (PA_6_SPI0_MISO | PORT_PS_UP_ENABLE)); \
_CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, SPI_CS1, SPI_CS1, (PORT_SRE_FAST | PORT_DSE_HIGH));\
_CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, SPI_CS2, SPI_CS2, (PORT_SRE_FAST | PORT_DSE_HIGH));\
SPI0_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE); \
SPI0_BR = (SPI_BR_SPPR_PRE_4 | SPI_BR_SPR_DIV_2); \
(void)SPI0_S; (void)SPI0_D;

I tried POWER_UP(4, SIM_SCGC4_SPI0) and POWER_DOWN(4, SIM_SCGC4_SPI0) and that reduces the current to half. How can I deconfigure the other peripherals _CONFIG_PERIPHERAL and _CONFIG_DRIVE_PORT_OUTPUT_VALUE?
« Last Edit: August 18, 2020, 10:16:56 PM by Raffaele »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3240
    • View Profile
    • uTasker
Re: SPI configs increases current absorption of 70mA
« Reply #1 on: August 18, 2020, 10:59:21 PM »
Hi

Such a high current consumption is not normal. If the SPi is not actuall sending something I would not expect it to contribute much additional consumption - maximum a few 10..100uA.

It may be that one of the SPI lines is short circuiting with something; try not initialising the pins at all to see the effect of simply enabling the SPI module. If the current is then low try enabling each of the lines individually to see which one causes the problem.

Regards

Mark

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: SPI configs increases current absorption of 70mA
« Reply #2 on: August 19, 2020, 12:05:36 AM »
Thanks  Mark,

so the problem seems to be caused by SPI0_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE); if I remove this line the current consumption stays at 3mA.
Now you see I have two chip selects, if SPI0_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE);  is there and I only use the first chip select, the current is 47mA. If I add the second chip select the current goes up to 80mA. If I keep both chip selects but remove SPI0_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE);, as I said, the current goes back to 3mA

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3240
    • View Profile
    • uTasker
Re: SPI configs increases current absorption of 70mA
« Reply #3 on: August 20, 2020, 02:39:36 AM »
Hi

I would still try disabling the pins since when the SPI is enabled it will start driving outputs.
Also - is the additional current consumption maybe due to the SPI slaves rather than the KL03? The SPI slaves may consume current when selected by their CS lines).
Are the SPI slaves connected correctly (eg. is it possible that their SOUT lines are connected to the KL03's SOT line rather than SIN?)

Regards

Mark

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: SPI configs increases current absorption of 70mA
« Reply #4 on: August 21, 2020, 04:38:47 PM »
Fantastic, Mark!

I tried the lines 1 by 1 and I found out that the issue was the clock. It interfered with the clock of the device it is connected to, as the other device can be master or slave but I hadn't configured it as slave.

Great,
thanks

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: SPI configs increases current absorption of 70mA
« Reply #5 on: August 25, 2020, 05:32:30 PM »
A slightly unrelated question.

_CONFIG_PERIPHERAL(B, 0, PB_0_SPI0_SCK) defines the CLK pin. For the KL03, the family manual says that PB_0, PA_9 or PB_11 can be used as clock lines (depending on the chip).

I am assuming that if I want the clock on PA_9, then I need to do:
_CONFIG_PERIPHERAL(A, 9, PA_9_SPI0_SCK);

and add:

#define PA_09_SPI0_SCK PORT_MUX_ALT3, as PA_09_SPI0_SCK is not defined in the code.

Does it sound correct?

But, I can't use a generic GPIO pin for the CLK, like PA_8, can I?
« Last Edit: August 25, 2020, 05:48:42 PM by Raffaele »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3240
    • View Profile
    • uTasker
Re: SPI configs increases current absorption of 70mA
« Reply #6 on: August 27, 2020, 12:33:47 PM »
Hi

The alternative settings are correct as you have defined them - it is also not possible to use a normal GPIO for clocking if the SPI is used (any GPIO be used by bit-banging, but all signals would need to be bit banged and thus the SPI would not be used at all).

Here are the complete KL03 SPI0 MUX settings:

    #define PA_5_SPI0_SS_b               PORT_MUX_ALT3
    #define PB_10_SPI0_SS_b              PORT_MUX_ALT3
    #define PB_0_SPI0_SCK                PORT_MUX_ALT3
    #define PA_9_SPI0_SCK                PORT_MUX_ALT3
    #define PA_7_SPI0_MOSI               PORT_MUX_ALT3
    #define PA_8_SPI0_MOSI               PORT_MUX_ALT3
    #define PA_7_SPI0_MISO               PORT_MUX_ALT2
    #define PA_6_SPI0_MISO               PORT_MUX_ALT3
    #define PB_11_SPI0_MISO              PORT_MUX_ALT3


Regards

Mark


Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: SPI configs increases current absorption of 70mA
« Reply #7 on: October 01, 2020, 11:39:21 PM »
Related to this topic, so I don't open a new one. After configuring an SPI interface, by calling INITIALISE_SPI_SD_INTERFACE() as defined below, is it possible to disable/undefine it?



 
This is my config, just regular SPI:

Code: [Select]
#define INITIALISE_SPI_SD_INTERFACE()  POWER_UP(4, SIM_SCGC4_SPI0); \
                        _CONFIG_PERIPHERAL(B, 0, PB_0_SPI0_SCK); \
_CONFIG_PERIPHERAL(A, 7, (PA_7_SPI0_MOSI | PORT_SRE_FAST | PORT_DSE_HIGH)); \
_CONFIG_PERIPHERAL(A, 6, (PA_6_SPI0_MISO | PORT_PS_UP_ENABLE)); \
_CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, SPI_CS1, SPI_CS1, (PORT_SRE_FAST | PORT_DSE_HIGH));\
_CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, SPI_CS2, SPI_CS2, (PORT_SRE_FAST | PORT_DSE_HIGH));\
SPI0_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE); \
SPI0_BR = (SPI_BR_SPPR_PRE_4 | SPI_BR_SPR_DIV_2); \
(void)SPI0_S; (void)SPI0_D;


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3240
    • View Profile
    • uTasker
Re: SPI configs increases current absorption of 70mA
« Reply #8 on: October 02, 2020, 02:50:20 PM »
Hi

The SPI operation can be disabled by setting SPI0_C1 = 0;
And by powering down the peripheral POWER_DOWN(4, SIM_SCG4_SPI0);
Then you can reconfigure the pins for other functions too.

Regards

Mark