How to improve the baud of SPI for PSoC4 CY8C4025?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
idream
Level 3
Level 3
50 sign-ins First comment on blog 10 replies posted

I only use the MOSI of the SPI to send data, and there is no need for oversampling, how can I increase the rate of the SPI?

I See the max baud of SPI is 4MHz, and I need it to be 8MHz, the oversample is at least 6, how to config it to 3??

the chip is CY8C4025, thanks.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Today, I could run some test.

I used my board with CY8C4146LQI-S433 (48MHz) aka TSoC.

I set IMO to 24MHz, so logically it should be compatible with 4025.

020-HFC.JPG

Then I used Clock_24MHz for the SPI-Clock

022-SPI_clock.JPG

As I used  P2[2] for SCLK, P2[3] for ss0, P3[3] for MOSI, SCB1 was used.
So I had to use SCB1_CTRL register instead of SCB0_CTRL register.

uint32_t *REG_SCB1_CTRL = (uint32_t *)0x40090000 ;

set_ovs() function

void set_ovs(uint8_t ovs)
{
    uint32_t reg_value, ovs_value ;
    reg_value = *REG_SCB1_CTRL & 0xFFFFFFF0 ; // clear [3:0]
    ovs_value = ovs ; // specifying the oversample value - 1   
    *REG_SCB1_CTRL = reg_value | ovs_value ;   
}

 

When OVS = 6 -> OVS[3:0] = 5 

Oversampling = 6 (ovs[3:0] = 5) sclk = 4 MHz

SDS00002.png

 

set_ovs(4), OVS = 5

Oversampling = 5 (ovs[3:0] = 4) sclk = 4.8 MHz

SDS00003.png

 

set_ovs(3), OVS = 4

Oversampling = 4 (ovs[3:0] = 3) sclk =  5.8 MHz

SDS00004.png

 

set_ovs(2), OVS = 3

Oversampling = 3 (ovs[3:0] = 2) sclk =  7.1 MHz

SDS00005.png

 

set_ovs(1), OVS = 2

Oversampling = 2 (ovs[3:0] = 1) sclk = 11.1 MHz

SDS00006.png

SDS00007.png

 

set_ovs(0), OVS = 1 (?)

Oversampling = 1 (ovs[3:0] = 0) sclk = 16.4 MHz (Note: probably not usable)

SDS00008.png

So, the good news is yes, we seem to be able to change the oversampling ratio.

But the bad news is since the frequncy is approaching or exeeding the device capability,
it is difficult to judge if a particular oversampling ratio is usable.

moto

 

View solution in original post

11 Replies
NXTY_Tatebayasi
Level 5
Level 5
Distributor - NEXTY (Japan)
50 questions asked 25 likes received 250 sign-ins

Hi, @idream -san,

Which tool do you use to develop your PSoC4000S?
It has the option to develop with Modus tool box or PSoC Creator.

Best Regards,

Hi NXTY,

I use PSoC Creator.

 

0 Likes
NXTY_Tatebayasi
Level 5
Level 5
Distributor - NEXTY (Japan)
50 questions asked 25 likes received 250 sign-ins

Hi, @idream -san,

The baud rate is in Hz, not bps, so you will need to change the reading, but if you are using PSoC Creator, you can set them on the component.

Click on the "Datasheet" button in the lower left corner to find detailed documentation of SCBcomponent.
I recommend you to read the section on SPI in this document.

NXTY_Tatebayasi_0-1706505824266.png

 

Best Regards,

lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

If the maximum frequency of your 4025 is 48MHz, we could hack something like below

schematic

001_schematic.JPG

Design Wide Resources (DRW) > Clocks

002-clock.JPG

SPI config

003-SPI.JPG

Just in case, I removed MISO

004-SPI_Pins.JPG

main.c

Note: Actually, I did not need "stdio.h" here

#include "project.h"
#include "stdio.h"

#define STR_LEN 64
        
int main(void)
{      
    uint8_t data ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */

    SPI_Start() ;
          
    for(;;) {
        SPI_SpiUartWriteTxData(data++) ;
    }
}

As I could not find a board with 4025, I tried with 4146 and my oscilloscope wave was something like below.

It seems the sclk is about 8MHz, but I wonder how reliable this SPI module is,

may be you need to test well before put this in real use.

SDS00002.png

Attached is the 4025 version and 4146 version of my test project.

(And I could test only 4146 version)

moto

Hi  , thanks.

But you use 4045 and it can be set 48MHz, but the 4025 can't set IMO 48Mhz and the max is 24MHz,

So the SPI just config the max speed is 4MHz, as the oversample is at least is 6.

How to hack the 4025 to 4045 ??

 

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

But you use 4045 and it can be set 48MHz,

Oops, it's my bad. I was trying to select 4025 but as I was hoping to use 48MHz,
I accedintally chose 4045 without noticing that it was not "4025".

Returning to the story, yes, it seems that 4025 supports up to 24 MHz for IMO.

So I'm afraid that you can not drive a SPI module in 48MHz clock 
unless you connect the clock terminal of the module to an external clock (ExtClk) 48MHz.
But even if you could do this, I wonder if the SPI module driven in 48MHz is usable in a device of 24MHz.

I also tried to bitbang a couple of GPIOs to emulate SCLK and MOSI,
but as GPIO the fastest I could get was around 315KHz or so.

So, if you really need 8MHz SPI, I would recommend you to use a faster device.

moto

 

Hi   ,

thanks.

How to change the oversample  from 6 to 4 or 2??

I didn't need MISO.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi, @idream

First of all, as I wrote in my first response, we are talking about out side of the "supported" range,
what I would call hack, so let's not surprise if the value we specify does not work in the real world.

Having written above, in the PSoC 4000 Family: PSoC 4 Registers Technical Reference Manual (TRM)

https://www.infineon.com/dgdl/Infineon-PSoC_4000_Family_PSoC_4_Registers_Technical_Reference_Manual_...

In the chapter 6.1.1 SCB_CTRL, bit [3:0] is OVS[3:0].

010_SCB_CTRL_Reg.JPG

And the description reads...

011-cont.JPG

So, technically we may be able to write 0x0 ~ 0x2 in the SCB_CTRL[3:0], although the defined minimum is 3

by doing something like below.

    uint32_t reg_value, ovs_value ;
    uint32_t *REG_SCB_CTRL = (uint32_t *)0x40060000 ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */

    SPI_Start() ;
    SPI_Stop() ;
    reg_value = *REG_SCB_CTRL & 0xFFFFFFF0 ; // clear [3:0]
    ovs_value = 0x00 ; // specifying the oversample value - 1
    *REG_SCB_CTRL = reg_value | ovs_value ;
    SPI_Enable() ;

As I'm out of my office, I have not been able to test this.

moto

 

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Again, I'm sorry, I made a mistake.

4025 was not 4000 series, but it is 4000S series.

So we must refer to the PSoC 4000S Registers Technical Reference Manual.

The Register for SCB Control is now named "SCB0_CTRL"

020-SCB0_CTRL.JPG

 And the description of OVS[3:0] bits is

021-OVS.JPG

 

So in my previous post, the address which was 0x40060000 should be 0x40080000 for 4000S

moto

lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Today, I could run some test.

I used my board with CY8C4146LQI-S433 (48MHz) aka TSoC.

I set IMO to 24MHz, so logically it should be compatible with 4025.

020-HFC.JPG

Then I used Clock_24MHz for the SPI-Clock

022-SPI_clock.JPG

As I used  P2[2] for SCLK, P2[3] for ss0, P3[3] for MOSI, SCB1 was used.
So I had to use SCB1_CTRL register instead of SCB0_CTRL register.

uint32_t *REG_SCB1_CTRL = (uint32_t *)0x40090000 ;

set_ovs() function

void set_ovs(uint8_t ovs)
{
    uint32_t reg_value, ovs_value ;
    reg_value = *REG_SCB1_CTRL & 0xFFFFFFF0 ; // clear [3:0]
    ovs_value = ovs ; // specifying the oversample value - 1   
    *REG_SCB1_CTRL = reg_value | ovs_value ;   
}

 

When OVS = 6 -> OVS[3:0] = 5 

Oversampling = 6 (ovs[3:0] = 5) sclk = 4 MHz

SDS00002.png

 

set_ovs(4), OVS = 5

Oversampling = 5 (ovs[3:0] = 4) sclk = 4.8 MHz

SDS00003.png

 

set_ovs(3), OVS = 4

Oversampling = 4 (ovs[3:0] = 3) sclk =  5.8 MHz

SDS00004.png

 

set_ovs(2), OVS = 3

Oversampling = 3 (ovs[3:0] = 2) sclk =  7.1 MHz

SDS00005.png

 

set_ovs(1), OVS = 2

Oversampling = 2 (ovs[3:0] = 1) sclk = 11.1 MHz

SDS00006.png

SDS00007.png

 

set_ovs(0), OVS = 1 (?)

Oversampling = 1 (ovs[3:0] = 0) sclk = 16.4 MHz (Note: probably not usable)

SDS00008.png

So, the good news is yes, we seem to be able to change the oversampling ratio.

But the bad news is since the frequncy is approaching or exeeding the device capability,
it is difficult to judge if a particular oversampling ratio is usable.

moto

 

Hi , thanks you very much,  it is ok.

I have modify it as :

void set_ovs(uint8_t ovs)
{
uint32_t reg_value ;
reg_value = WSDSPI_CTRL_REG & (~WSDSPI_CTRL_OVS_MASK) ; // clear [3:0]
// specifying the oversample value - 1
WSDSPI_CTRL_REG = reg_value | ovs ;
}