Hardware SPI 8-bit in STM32G071

General discussion on mikroPascal PRO for ARM.
Post Reply
Author
Message
DanilinS
Posts: 16
Joined: 15 Feb 2015 21:30

Hardware SPI 8-bit in STM32G071

#1 Post by DanilinS » 01 Aug 2020 07:41

NUCLEO-G071RB ( chip STM32G071RB ) + SSD1309 ( SPI 8-bit)
Initialization and use:
Ini:

Code: Select all

    GPIO_Alternate_Function_Enable(@_GPIO_MODULE_SPI2_PD134);
 
    SPI2_Init_Advanced(_SPI_FPCLK_DIV8, (_SPI_8_BIT OR _SPI_MASTER OR _SPI_CLK_IDLE_LOW
                       OR _SPI_FIRST_CLK_EDGE_TRANSITION OR _SPI_MSB_FIRST
                       OR _SPI_SS_ENABLE OR _SPI_SSM_ENABLE OR _SPI_SSI_0),
                       @_GPIO_MODULE_SPI2_PD134);
Use:

Code: Select all

procedure  OLED_write(value: byte; control_byte: byte);
begin
    DC := (control_byte and 0x01);
    CS := LOW;
    SPI2_Write(value);
    CS := HIGH;
end;
During debugging, it turned out that it outputs 16 bits to the bus. This leads to the inoperability of OLED.

Now I have launched a project on a software SPI. But I want to use hardware SPI. Is it possible?

And further: mikroProg Suite For ARM v1.6.1" Does not detect "Detect MCU".
Logic analyzer screenshot
Logic analyzer screenshot
16bit_out.png (126.56 KiB) Viewed 1624 times

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: Hardware SPI 8-bit in STM32G071

#2 Post by AntiMember » 03 Aug 2020 19:12

Well, while the mikroe are silent, I can suggest (Ну пока микрое молчат, могу предложить) :

GPIO_Alternate_Function_Enable(@_GPIO_MODULE_SPI2_PD134);

SPI2_Init_Advanced(_SPI_FPCLK_DIV8, (_SPI_8_BIT OR _SPI_MASTER OR _SPI_CLK_IDLE_LOW
OR _SPI_FIRST_CLK_EDGE_TRANSITION OR _SPI_MSB_FIRST
OR _SPI_SS_ENABLE OR _SPI_SSM_ENABLE OR _SPI_SSI_0),
@_GPIO_MODULE_SPI2_PD134);
SPI2_CR1.B6 := 0; //disable SPI2
SPI2_CR2.B8 := 1; //
SPI2_CR2.B9 := 1; // set 8 bit data
SPI2_CR2.B10 := 1; //
SPI2_CR2.B11 := 0; //
SPI2_CR1.B6 := 1; //enable SPI2

SPIx_CR2 Bits 11:8 DS[3:0]: Data size
These bits configure the data length for SPI transfers.
0000: Not used
0001: Not used
0010: Not used
0011: 4-bit
0100: 5-bit
0101: 6-bit
0110: 7-bit
0111: 8-bit
1000: 9-bit
1001: 10-bit
1010: 11-bit
1011: 12-bit
1100: 13-bit
1101: 14-bit
1110: 15-bit
1111: 16-bit
If software attempts to write one of the “Not used” values, they are forced to the value “0111”
(8-bit)
Note: These bits are not used in I2S mode.

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Hardware SPI 8-bit in STM32G071

#3 Post by stefan.filipovic » 04 Aug 2020 14:46

Hi,

Unfortunately, it seems there's a bug in the compiler for the STM32G0xx family which doesn't allow setting SPI in 8-bit mode.
It's been forwarded to the developers. Hopefully, it will be fixed with the compiler updates.
I apologize for the inconvenience caused by this.

Kind regards,
Stefan Filipović

Post Reply

Return to “mikroPascal PRO for ARM General”