cancel
Showing results for 
Search instead for 
Did you mean: 

SPC58: SPI2 with two chip selects

SMay
Associate II

Hi.

I want to use DPI2 located at pins 66 (miso), 68 (mosi) and 112 (clock) to control two different SPI slave devices. Pin 57 (CS0) and pin 64 (CS2) are wired to the respective chip selects.

Then I used the wizards to generate application code for SPI2, using CS0 in hardware. Works like a charm.

But how can I add the second device, also using SPI2 and a different chip select? When I try to duplicate my SPI setting and changing the chip select line, the application stop using the former CS0 completely.

Controller is SPC58EC80E5QMC0, using SPC5studio 6 "asimov".

Thanks.

Edit: SPC5Studio offers options like hardware continuous, hardware discontinuous, software. Why is there no documentation, what those options actually do?

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions

Hi SMay,

about the question regarding the SPI, you should be able to change switch the configuration in 4ms.

About the eMIOS configuration, let me suggest to give a look to the example included in SPC5Studio (SPC58ECxx_RLA PWM-ICU Test Application). If you are not able to solve the issue, please, share your eMIOS/ pins configurations. I will check them.

Regards,

Luigi

View solution in original post

11 REPLIES 11
zambrano.luigi
Senior III

Hi,

you have to define 2 different DSPI configurations for the Master, one of them with the CS = CS0 and the other one with the CS = CS2. Then, when you want to communicate with the DSPI connected with the CS0, you have to load the first configuration

 spi_lld_start(&SPID3, &spi_config1);

 spi_lld_exchange(&SPID3, 4, txbuf, rxbuf);

 spi_lld_stop(&SPID3);

Instead, when you want to communicate with the DSPI connected with CS2, you have to load the second configuration

 spi_lld_start(&SPID3, &spi_config2);

 spi_lld_exchange(&SPID3, 4, txbuf, rxbuf);

 spi_lld_stop(&SPID3);

Regards,

Luigi

SMay
Associate II

Hi Luigi,

thanks for your reply. I have to reset watchdog timers in both SPI slaves in order to prevent a reset. Between wd resets, I have to send commands.

The frames are 4-5ms apart. Is the change of config fast enough to have it swapped every 4ms?

Regards,

SMay

SMay
Associate II

I also have two additional questions:

I want to have a easy and simple PWM at pin 6, eMIOS0-UC4. I used the pinmap editor to assign it to eMIOS 0 channel 4, set it to active low.

I call

pwm_lld_start(&PWMD5, &pwm_config_PWM0); during startup and afterwards

pwm_lld_enable_channel(&PWMD5, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD5, 5000), 100, 0, 0);

But the pin sits idle at 5V without any change.

Is there any documentation regarding the tons of options available in the GUI? I found a few help files under components\spc58ecxx_low_level_drivers_component_rla\doc, but the don't help that much.

Thanks.

Hi SMay,

about the question regarding the SPI, you should be able to change switch the configuration in 4ms.

About the eMIOS configuration, let me suggest to give a look to the example included in SPC5Studio (SPC58ECxx_RLA PWM-ICU Test Application). If you are not able to solve the issue, please, share your eMIOS/ pins configurations. I will check them.

Regards,

Luigi

SMay
Associate II

Hey Luigi,

thanks for your reply. After some confusion I was able to find the PWM-ICU application, because it is for a different type of microcontroller. Upon looking through the code I found that I was doing the exact same steps.

Ultimately I found the problem: The clocks and dividers where set up in order to produce a PWM width of one tick. I configured it to 50% duty cycle, and 50% of 1 always yielded 0. After adjustig the clocks and dividers, it is now working.

I think I also found a bug in either spc5studion or in your libraries. I am using the SPC58EC-DISP discovery kit, which is attached to CAN1_0 and CAN4_1. I wasnt able to get CAN4_1 working, so I used the wizard to create a sample application.

There seems to be a bug addressing the CAN4_1. The pinmap editor has to be set for module 4_1, but loading the respective CAN driver would mean CAND10, which does not work. You have to select CAN1_1 and load driver CAND7, as does the example project. Otherwise, It will not work.

zambrano.luigi
Senior III

Hi SMay,

the CAN pins defined in the Board Component of the CAN test application for SPC58EC Discovery are not important for the correct execution of the test application because the 2 CANs used by it are connected in loopback. If you enable the CAN10 (MCAN4 of CAN subsystem 1) and replace in the main "CAN7" with "CAN10", the test application will continue to work independently from the CAN pins defined in the Board Component. 

Please, let me underline that if you want to disable the loopback features and connect physically the 2 CANs, it is necessary that each CAN is connected to a CAN transceiver, otherwise the CAN communication will fail. 

Regards,

Luigi

SMay
Associate II

Hi Luigi,

I have a project pcb which has the same CAN connections as the discovery board. Loopback is disabled, it only works if I select 4_1 for the pins and 1_1 for the rest of the system.

Right now I am back at the PWM problem again. I want to use pin 11, eMIOS0_UC8 or as a fallback eMIOS1_UC10.

eMIOS0 group0 ends at channel7, so it has to be group1. It generates code for PWM driver 9, OPWMB, and I call the same function but replaced PWMD5 with PWMD9 and the config with a duplicate and adapted version of the working config. The pin sits idle at 2,5V.

How can I find out why UC8 is not working?

Regards

zambrano.luigi
Senior III

Hi,

as specified in the User Manual within the folder doc of the Low Level Driver Component, between the eMIOS channels and the driver instances there is the relationship summarized in the following picture:

0693W000007ZiakQAC.jpgAs you can see from the picture, the channel eMIOS0_UC8 is not available. This because, except for the first eMIOS group (eMIOS0 group0), the first channel of each group is used as counter for the other channels of the same group. So, for example, the channel eMIOS0 ch8 is the counter for the channels eMIO0 ch9-ch15. These channels (eMIO0 ch9-15) are managed as a unique driver (PWMD9) with 7 channels (0-6) with the same period. If you need to use the eMIO0_CH8, the driver must be modified.

Regards,

Luigi

SMay
Associate II

Thanks for your reply. Like I said, as a fallback I'd be ok with using eMIOS1_10, which is the same pin. According to the spec, that would make it PWMD13, channel 1.

So I configured it to UC10_1 in the pinmap editor, called:

pwm_lld_start(&PWMD5, &pwm_config_BR0_PWM);

pwm_lld_start(&PWMD13,&pwm_config_BR1_PWM);

And afterwards

pwm_lld_enable_channel(&PWMD5, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD5, 5000), 0, 0, 0);

pwm_lld_enable_channel(&PWMD13, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD13,5000), 0, 0, 0);

The call for PWMD5 works, I get a PWM at pin6. The configs are identical, ~39kHz PWM frequency and set to the respective eMIOS group & channel.

Where should I look for errors?