没有合适的资源?快使用搜索试试~ 我知道了~
首页AN5413-S32K14x Series Cookbook(例程)
资源详情
资源评论
资源推荐
NXP Semiconductors
Application Note
Document Number: AN5413
Rev. 0, 03/2017
Contents
1 Introduction
This application note provides software examples and
describes necessary startup steps needed to help users get
started with S32K14x series MCUs.
Complete source code and projects are available in a
separate zip file at nxp.com. Projects are implemented
using NXP’s S32 Design Studio and tested on the
S32K144 evaluation board. To access the projects in the
zip file, either:
• Windows: unzip archive file to a folder
• S32 Design Studio: use File - Import and select
the zip file.
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Software examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1 Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Hello World + Clocks . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Hello World + Interrupts. . . . . . . . . . . . . . . . . . . . . 11
2.4 DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.5 Timed I/O (FTM) . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.6 ADC - SW Trigger . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.7 UART. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.8 SPI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.9 CAN 2.0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.10 CAN FD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
3 Startup code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.1 S32 Design Studio, S32K14x flash target . . . . . . . 63
4 Header files cheat sheet . . . . . . . . . . . . . . . . . . . . . . . . 64
5 Adding projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
S32K14x Series Cookbook
Software examples and startup code to exercise
microcontroller features
S32K14x Series Cookbook, Rev. 0, March 2017
Software examples
NXP Semiconductors2
2 Software examples
The table below lists the examples in this application note. The three Hello World examples are intended
to be base projects that can be copied and code added to create a new project.
Table 1. List of examples
Example Programs Summary
Hello World hello Simplest project:
• Configure GPIO
• Output to LED follows switch input
Hello World + Clocks hello_clocks Perform common initialization for clocks and LPIT:
• Initialize System Oscillator (SOSC) for 8 MHz crystal
• Initialize SPLL with 8 MHz SOSC input to provide 80 MHz clock
• Change Normal RUN mode clock from default FIRC to 160 MHz SPLL
(before dividers)
• Initialize LPIT channel to count 40M clocks (1 second timeout)
• Toggle output to LED every LPIT timeout
Hello World + Clocks +
Interrupts
hello_clocks_interrupts The Hello World + Clock example is modified to service the PIT channel
timeout with an interrupt service route:
• Initialize system clock to 80 MHz
• Initialize an LPIT channel for 1 second timeout and enable its interrupt
• Wait forever
• At LPIT timeout interrupt, toggle output to LED
DMA eDMA Transfer a string of bytes to a single byte location:
• Initialize a Transfer Control Descriptor (TCD)
• Use software (instead of peripheral DMA requests) to initiate transfers
Timed I/O (FTM) FTM Perform common timed I/O functions with FTM:
• Module counter initialization
• Pulse Width MOdulation
• Output Compare
• Input Capture
ADC - SW Trigger ADC Perform simple analog to digital conversions using software trigger:
• Initialize ADC for SW trigger, continuous mode
• Loop:
- Convert channel connected to pot on evaluation board
- Scale result to 0 to 5000 mV
- Light evaluation board LEDs to reflect voltage level
- Convert channel connected to the ADC high reference voltage
UART UART Transmit and receive characters:
• Initialize UART for 9600 baud, 1 stop, no parity
• Loop:
- Transmit string, then a prompt character on new line
- When character is received, echo it back
SPI LPSPI Transmit and receive a SPI frame:
• Initialize LPSPI for 1M Baud, PCS3 which is connected to SPC on EVB
• Wait for Tx FIFO to have at least one available slot then issue transmit
• Wait for Rx FIFO to have at least one received frame then read data
Software examples
S32K14x Series Cookbook, Rev. 0, March 2017
NXP Semiconductors 3
CAN 2.0 FlexCAN Transmit and receive an eight byte CAN 2.0 message at 500 KHz:
• Initialize FlexCAN & Message Buffer 4 to receive a message
• Transmit one frame using Message Buffer 0
• Loop:
- If Message Buffer 4 received message flag is set, read message
- If Message Buffer 0 transmit done flag is set, transmit another message
CAN FD FlexCAN_FD Transmit and receive a 64 byte CAN FD message at 500 KHz & 1 or 2 MHz:
• Initialize FlexCAN & Message Buffer 4 to receive a message
• Transmit one frame using Message Buffer 0
Loop:
- If Message Buffer 4 received message flag is set, read message
- If Message Buffer 0 transmit done flag is set, transmit another message
Table 1. List of examples
Example Programs Summary
S32K14x Series Cookbook, Rev. 0, March 2017
Software examples
NXP Semiconductors4
2.1 Hello World
2.1.1 Description
Summary: This short project is a starting point to learn GPIO. An input is polled to detect a high or low
level. An output is set depending on input state. If running code on the S32K14x evaluation board, pressing
button 0 lights up the blue LED per the diagram below.
Figure 1. Hello World block diagram
2.1.2 Design
• Initialization before main:
— Define interrupt addresses (such as Reset_Handler) and flash configuration
— Initialize stack pointer, registers
— Disable watchdog if configured
— Initialize vector table
— Copy variables from ROM to RAM and zero out data section (.bss)
— Unmask interrupts
• Disable watchdog
• Enable clocks to GPIO modules and configure GPIO ports:
— PTC12: GPIO input (goes to BTN 0 on evaluation board)
— PTD0: GPIO output (goes to blue LED)
• Loop:
— If BTN0 is pressed (input = 1),
– Turn LED on (output = 0)
— else (input = 0)
– Turn LED off (output = 1)
PTD0
S32K144
GPIO
PC12
BTN0
VDD
VDD
Blue
(SW2)
LED
S32K144 EVB
Software examples
S32K14x Series Cookbook, Rev. 0, March 2017
NXP Semiconductors 5
2.1.3 Code
2.1.3.1 hello.c
#include "S32K144.h" /* include peripheral declarations S32K144 */
#define PTD0 0 /* Port PTD0, bit 0: FRDM EVB output to blue LED */
#define PTC12 12 /* Port PTC12, bit 12: FRDM EVB input from BTN0 [SW2] */
void WDOG_disable (void){
WDOG->CNT=0xD928C520; /*Unlock watchdog*/
WDOG->TOVAL=0x0000FFFF; /*Maximum timeout value*/
WDOG->CS = 0x00002100; /*Disable watchdog*/
}
int main(void) {
int counter = 0;
WDOG_disable();
/* Enable clocks to peripherals (PORT modules) */
PCC-> PCCn[PCC_PORTC_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT C */
PCC-> PCCn[PCC_PORTD_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT D */
/* Configure port C12 as GPIO input (BTN 0 [SW2] on EVB) */
PTC->PDDR &= ~(1<<PTC12); /* Port C12: Data Direction= input (default) */
PORTC->PCR[12] = 0x00000110; /* Port C12: MUX = GPIO, input filter enabled */
/* Configure port D0 as GPIO output (LED on EVB) */
PTD->PDDR |= 1<<PTD0; /* Port D0: Data Direction= output */
PORTD->PCR[0] = 0x00000100; /* Port D0: MUX = GPIO */
for(;;) {
if (PTC->PDIR & (1<<PTC12)) { /* If Pad Data Input = 1 (BTN0 [SW2] pushed) */
PTD-> PCOR |= 1<<PTD0; /* Clear Output on port D0 (LED on) */
}
else { /* If BTN0 was not pushed */
PTD-> PSOR |= 1<<PTD0; /* Set Output on port D0 (LED off) */
}
counter++;
}
剩余66页未读,继续阅读
从前有座shan
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0