I could not run SPI on Microbus 1-5

General discussion on mikroC PRO for ARM.
Post Reply
Author
Message
fame12tr@hotmail.com
Posts: 9
Joined: 01 Feb 2021 12:40

I could not run SPI on Microbus 1-5

#1 Post by fame12tr@hotmail.com » 06 Feb 2023 22:07

I would like to ask for your help regarding the subject I will explain below.
I have Fusion for STM32 V8 board and 7" TFT Capacitive display.
There is STM32F407ZG MCU on the board.

I connected an external SD card to this board, I wrote software that works over SPI3 using the following SPI definitions.
For SPI3, I used the PORTB 7-0 pinheader on the board.
PortB.3= SCK
Portb.4= MISO
Portb.5= MOSI
Portb.0= CS
(I cross-connect MISO and MOSI terminals on Board and SD connections)
The program reads Sector 0 from the SD Card with FAT32 and calculates the detail information of the inserted card and displays it on the TFT screen.
(Card Size, Free Cluster, Total Sector etc.)
The software works without any problems with the following SPI definition.

// Definitions for SPI3****************************************************
void initSPI(void)
{
SPI3_Init_Advanced(_SPI_FPCLK_DIV64, _SPI_MASTER | _SPI_8_BIT |
_SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION |
_SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1,
&_GPIO_MODULE_SPI3_PB345 );
}

void initFastSPI(void)
{
SPI3_Init_Advanced(_SPI_FPCLK_DIV2, _SPI_MASTER | _SPI_8_BIT |
_SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION |
_SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1,
&_GPIO_MODULE_SPI3_PB345 );
}
//********************************************************************

My problem is:
As I have marked in the attached pictures for SPI3,
I cannot run the same software using the SPI ends of the MCU I am using, which are connected to Microbus 4 or 5.
PortC.10= SCK
PortC.11= MISO
PortC.12= MOSI
Portb.0 = CS ( Microbus5 PWM pin)
(I cross-connect MISO and MOSI terminals on Board and SD connections)

I used the following SPI definition when using Microbus 5 SPI pins.

// SPI3 definitions in Microbus 5 SPI usage ***********************************

GPIO_Alternate_Function_Enable(&_GPIO_MODULE_SPI3_ PC10_11_12 );

void initSPI(void)
{
SPI3_Init_Advanced(_SPI_FPCLK_DIV64, _SPI_MASTER | _SPI_8_BIT |
_SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION |
_SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1,
&_GPIO_MODULE_SPI3_ PC10_11_12 );
}

void initFastSPI(void)
{
SPI3_Init_Advanced(_SPI_FPCLK_DIV2, _SPI_MASTER | _SPI_8_BIT |
_SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION |
_SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1,
&_GPIO_MODULE_SPI3_ PC10_11_12 );
}
//********************************************************************

Where am I doing wrong or what could be the reason why it doesn't work?
I am asking for your help in this matter.

Best Regards
Emrah CALISKAN
R&D Software Engineer
Attachments
mcu-card-for-stm32-stm32f407zg.jpg
mcu-card-for-stm32-stm32f407zg.jpg (307.19 KiB) Viewed 644 times
Resim2.jpg
Resim2.jpg (331.04 KiB) Viewed 644 times

Smart_Aleck
Posts: 16
Joined: 07 Feb 2023 20:45

Re: I could not run SPI on Microbus 1-5

#2 Post by Smart_Aleck » 07 Feb 2023 20:56

Hi,

using the mikroBUS sockets like mikroBUS4 or mikroBUS5 makes most sense, if you are using a Click Board.
Are you using a Click Board?

If so, very likely the SPI CS is not on portB.0, but somewhere else.

What exactly isn't working?

rgs
SA

fame12tr@hotmail.com
Posts: 9
Joined: 01 Feb 2021 12:40

Re: I could not run SPI on Microbus 1-5

#3 Post by fame12tr@hotmail.com » 08 Feb 2023 20:32

Hi
I am not using any Click board.
I connected an external SD card to the Fusion for STM32 V8 card.

While connecting the card ends to the Microbus5 SPI ends, I saw that the CS end was PortD.7.
But since I don't use Click board
I connected it to Portb.0 because I thought it should not be a necessity for CS to be connected to Portd.7.
I defined Portb.0 for CS in the software, but it didn't work.
Currently I changed the CS end to Portd.7 and it worked.

But I could not understand the reason for this necessity.
Thanks

E.Caliskan
Regards

Smart_Aleck
Posts: 16
Joined: 07 Feb 2023 20:45

Re: I could not run SPI on Microbus 1-5

#4 Post by Smart_Aleck » 09 Feb 2023 13:46

Hi,

good to hear that its working, even it is a little bit different than expected.

Is there a space character between the "_GPIO_MODULE_SPI3_" and "PC10_11_12" ?

kind regards
SA

fame12tr@hotmail.com
Posts: 9
Joined: 01 Feb 2021 12:40

Re: I could not run SPI on Microbus 1-5

#5 Post by fame12tr@hotmail.com » 13 Feb 2023 08:13

Hi

"_GPIO_MODULE_SPI3_" and "PC10_11_12"
There are no spaces between definitions.

In SPI definitions, MOSI, MISO and CLK ends are mandatory, but CS ends are not.
Because I have tried and seen it working by changing the CS terminals with very different ports in various SPIx applications in my previous projects, I am sure of that.

I reviewed the open schematic of the STM32F407ZG MCU processor again.
I have not understood the reason yet, but as I said, there is no problem at the moment, the software is working.

Regards
E.Caliskan

Post Reply

Return to “mikroC PRO for ARM General”