How can I toggle the CS pin of SPI ports in K40x microcontroller at a certain rate ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I toggle the CS pin of SPI ports in K40x microcontroller at a certain rate ?

Jump to solution
1,738 Views
kbm
Contributor I

Hi All,

I am using PE with CodeWarrior to set the SPI port of microcontroller using in K40x256 tower system. Could anyone please explain how I can toggle the CS pin of the SPI port at a certain rate ? I need this to interface with a certain ADC.

Labels (1)
Tags (2)
0 Kudos
Reply
1 Solution
1,435 Views
BlackNight
NXP Employee
NXP Employee

Simply have the CS pin disabled:

The you can use the CS pin any way you want (e.g. as a Bit I/O pin).

Erich

View solution in original post

0 Kudos
Reply
6 Replies
1,435 Views
BlackNight
NXP Employee
NXP Employee

Hello,

you can use the CS pin as a normal general purpose pin. A simple solution would be to set up a timer interrupt with a given rate, and then toggle the CS pin from the interrupt service routine. You can check as well if that CS pin can be muxed say with a timer-out channel. If so, you could simply use a PWM signal to toggle the pin (e.g. Tutorial: PWM with Processor Expert).

Erich

1,435 Views
kbm
Contributor I

Hi Erich,

Thanks a lot ! I was wondering how I can change the clk rate of SPI ? I tried but it seems that the values are unachievable with the current settings.

test_pic.png

0 Kudos
Reply
1,435 Views
BlackNight
NXP Employee
NXP Employee

You set the SPI clock here:

pastedImage_0.png

The clock path is only to illustrate how that clock is built up.

Processor Expert can automatically select the prescalers for you, so you do not need to do this by hand.

Erich

1,435 Views
kbm
Contributor I

Thanks again ! In relation to the SPI pin how can I check if the CS pin can be MUXED ? In PE Components, there is an option CS demultiplexer but no option for multiplexer

0 Kudos
Reply
1,436 Views
BlackNight
NXP Employee
NXP Employee

Simply have the CS pin disabled:

The you can use the CS pin any way you want (e.g. as a Bit I/O pin).

Erich

0 Kudos
Reply
1,435 Views
kbm
Contributor I

Very helpful. Thanks !! I have got the SPI working now.. About handling data coming through the SPI, I have two ways to handle..

1. Pass from SPI to memory using DMA. Then from memory to PC using UART.

2. Pass from SPI directly to other SPI2. Then from SPI2 to PC.

Could you please let me know how I can implement 1 and 2. Could you please point to any tutorials ? Also, could you please with documentation for the microcontroller used in K40x256 as I am unable to find one, especially describing SPI and other peripherals..

Also,

Is there any way in Code Warrior I can watch variables in run time such as some compilers have the option of Live Watch ?

0 Kudos
Reply