These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***********************************************************************//**
frank26080115 0:bf7b9fba3924 2 * @file ssp_master.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example describes how to use SPP in master mode
frank26080115 0:bf7b9fba3924 4 * @version 2.0
frank26080115 0:bf7b9fba3924 5 * @date 21. May. 2010
frank26080115 0:bf7b9fba3924 6 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 7 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 8 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 9 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 10 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 11 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 12 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 13 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 14 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 15 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 16 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 17 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 18 **********************************************************************/
frank26080115 0:bf7b9fba3924 19 #include "lpc17xx_ssp.h"
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 22 #include "debug_frmwrk.h"
frank26080115 0:bf7b9fba3924 23 #include "lpc17xx_gpio.h"
frank26080115 0:bf7b9fba3924 24
frank26080115 0:bf7b9fba3924 25 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 26 /** @defgroup SSP_Master Master
frank26080115 0:bf7b9fba3924 27 * @ingroup SSP_Examples
frank26080115 0:bf7b9fba3924 28 * @{
frank26080115 0:bf7b9fba3924 29 */
frank26080115 0:bf7b9fba3924 30
frank26080115 0:bf7b9fba3924 31 /************************** PRIVATE DEFINTIONS ************************/
frank26080115 0:bf7b9fba3924 32 /** Max buffer length */
frank26080115 0:bf7b9fba3924 33 #define BUFFER_SIZE 0x40
frank26080115 0:bf7b9fba3924 34
frank26080115 0:bf7b9fba3924 35
frank26080115 0:bf7b9fba3924 36 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 37 uint8_t menu1[] =
frank26080115 0:bf7b9fba3924 38 "********************************************************************************\n\r"
frank26080115 0:bf7b9fba3924 39 "Hello NXP Semiconductors \n\r"
frank26080115 0:bf7b9fba3924 40 "SSP demo \n\r"
frank26080115 0:bf7b9fba3924 41 "\t - MCU: LPC17xx \n\r"
frank26080115 0:bf7b9fba3924 42 "\t - Core: ARM Cortex-M3 \n\r"
frank26080115 0:bf7b9fba3924 43 "\t - Communicate via: UART0 - 115200bps \n\r"
frank26080115 0:bf7b9fba3924 44 "\t An example of SSP using polling mode to test the SSP driver \n\r"
frank26080115 0:bf7b9fba3924 45 " This example uses SSP in SPI mode as master to communicate with an SSP slave device \n\r"
frank26080115 0:bf7b9fba3924 46 " The master and slave transfer together a number of data byte \n\r"
frank26080115 0:bf7b9fba3924 47 "********************************************************************************\n\r";
frank26080115 0:bf7b9fba3924 48 uint8_t menu2[] = "Demo terminated! \n\r";
frank26080115 0:bf7b9fba3924 49
frank26080115 0:bf7b9fba3924 50 // SSP Configuration structure variable
frank26080115 0:bf7b9fba3924 51 SSP_CFG_Type SSP_ConfigStruct;
frank26080115 0:bf7b9fba3924 52
frank26080115 0:bf7b9fba3924 53 // Tx buffer
frank26080115 0:bf7b9fba3924 54 uint8_t Tx_Buf[BUFFER_SIZE];
frank26080115 0:bf7b9fba3924 55
frank26080115 0:bf7b9fba3924 56 // Rx buffer
frank26080115 0:bf7b9fba3924 57 uint8_t Rx_Buf[BUFFER_SIZE];
frank26080115 0:bf7b9fba3924 58
frank26080115 0:bf7b9fba3924 59 /************************** PRIVATE FUNCTIONS *************************/
frank26080115 0:bf7b9fba3924 60 void print_menu(void);
frank26080115 0:bf7b9fba3924 61 void Buffer_Init(void);
frank26080115 0:bf7b9fba3924 62 void Error_Loop(void);
frank26080115 0:bf7b9fba3924 63 void Buffer_Verify(void);
frank26080115 0:bf7b9fba3924 64
frank26080115 0:bf7b9fba3924 65 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
frank26080115 0:bf7b9fba3924 66 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 67 * @brief Initialize buffer
frank26080115 0:bf7b9fba3924 68 * @param[in] None
frank26080115 0:bf7b9fba3924 69 * @return None
frank26080115 0:bf7b9fba3924 70 **********************************************************************/
frank26080115 0:bf7b9fba3924 71 void Buffer_Init(void)
frank26080115 0:bf7b9fba3924 72 {
frank26080115 0:bf7b9fba3924 73 uint8_t i;
frank26080115 0:bf7b9fba3924 74
frank26080115 0:bf7b9fba3924 75 for (i = 0; i < BUFFER_SIZE; i++) {
frank26080115 0:bf7b9fba3924 76 Tx_Buf[i] = i;
frank26080115 0:bf7b9fba3924 77 Rx_Buf[i] = 0;
frank26080115 0:bf7b9fba3924 78 }
frank26080115 0:bf7b9fba3924 79 }
frank26080115 0:bf7b9fba3924 80
frank26080115 0:bf7b9fba3924 81 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 82 * @brief Error Loop (called by Buffer_Verify() if any error)
frank26080115 0:bf7b9fba3924 83 * @param[in] none
frank26080115 0:bf7b9fba3924 84 * @return None
frank26080115 0:bf7b9fba3924 85 **********************************************************************/
frank26080115 0:bf7b9fba3924 86 void Error_Loop(void)
frank26080115 0:bf7b9fba3924 87 {
frank26080115 0:bf7b9fba3924 88 /* Loop forever */
frank26080115 0:bf7b9fba3924 89 while (1);
frank26080115 0:bf7b9fba3924 90 }
frank26080115 0:bf7b9fba3924 91
frank26080115 0:bf7b9fba3924 92
frank26080115 0:bf7b9fba3924 93 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 94 * @brief Verify buffer
frank26080115 0:bf7b9fba3924 95 * @param[in] none
frank26080115 0:bf7b9fba3924 96 * @return None
frank26080115 0:bf7b9fba3924 97 **********************************************************************/
frank26080115 0:bf7b9fba3924 98 void Buffer_Verify(void)
frank26080115 0:bf7b9fba3924 99 {
frank26080115 0:bf7b9fba3924 100 uint8_t i;
frank26080115 0:bf7b9fba3924 101 uint8_t *src_addr = (uint8_t *) &Tx_Buf[0];
frank26080115 0:bf7b9fba3924 102 uint8_t *dest_addr = (uint8_t *) &Rx_Buf[0];
frank26080115 0:bf7b9fba3924 103
frank26080115 0:bf7b9fba3924 104 for ( i = 0; i < BUFFER_SIZE; i++ )
frank26080115 0:bf7b9fba3924 105 {
frank26080115 0:bf7b9fba3924 106 if ( *src_addr++ != *dest_addr++ )
frank26080115 0:bf7b9fba3924 107 {
frank26080115 0:bf7b9fba3924 108 _DBG_("Verify error");
frank26080115 0:bf7b9fba3924 109 /* Call Error Loop */
frank26080115 0:bf7b9fba3924 110 Error_Loop();
frank26080115 0:bf7b9fba3924 111 }
frank26080115 0:bf7b9fba3924 112 }
frank26080115 0:bf7b9fba3924 113 }
frank26080115 0:bf7b9fba3924 114
frank26080115 0:bf7b9fba3924 115
frank26080115 0:bf7b9fba3924 116 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 117 * @brief Print Welcome menu
frank26080115 0:bf7b9fba3924 118 * @param[in] none
frank26080115 0:bf7b9fba3924 119 * @return None
frank26080115 0:bf7b9fba3924 120 **********************************************************************/
frank26080115 0:bf7b9fba3924 121 void print_menu(void)
frank26080115 0:bf7b9fba3924 122 {
frank26080115 0:bf7b9fba3924 123 _DBG(menu1);
frank26080115 0:bf7b9fba3924 124 }
frank26080115 0:bf7b9fba3924 125
frank26080115 0:bf7b9fba3924 126 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 127 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 128 * @brief c_entry: Main SSP program body
frank26080115 0:bf7b9fba3924 129 * @param[in] None
frank26080115 0:bf7b9fba3924 130 * @return int
frank26080115 0:bf7b9fba3924 131 **********************************************************************/
frank26080115 0:bf7b9fba3924 132 int c_entry(void)
frank26080115 0:bf7b9fba3924 133 {
frank26080115 0:bf7b9fba3924 134 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 135 SSP_DATA_SETUP_Type xferConfig;
frank26080115 0:bf7b9fba3924 136
frank26080115 0:bf7b9fba3924 137 /*
frank26080115 0:bf7b9fba3924 138 * Initialize SPI pin connect
frank26080115 0:bf7b9fba3924 139 * P0.15 - SCK;
frank26080115 0:bf7b9fba3924 140 * P0.16 - SSEL
frank26080115 0:bf7b9fba3924 141 * P0.17 - MISO
frank26080115 0:bf7b9fba3924 142 * P0.18 - MOSI
frank26080115 0:bf7b9fba3924 143 */
frank26080115 0:bf7b9fba3924 144 PinCfg.Funcnum = 2;
frank26080115 0:bf7b9fba3924 145 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 146 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 147 PinCfg.Portnum = 0;
frank26080115 0:bf7b9fba3924 148 PinCfg.Pinnum = 15;
frank26080115 0:bf7b9fba3924 149 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 150 PinCfg.Pinnum = 17;
frank26080115 0:bf7b9fba3924 151 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 152 PinCfg.Pinnum = 18;
frank26080115 0:bf7b9fba3924 153 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 154 PinCfg.Pinnum = 16;
frank26080115 0:bf7b9fba3924 155 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 156
frank26080115 0:bf7b9fba3924 157 /* Initialize debug via UART0
frank26080115 0:bf7b9fba3924 158 * – 115200bps
frank26080115 0:bf7b9fba3924 159 * – 8 data bit
frank26080115 0:bf7b9fba3924 160 * – No parity
frank26080115 0:bf7b9fba3924 161 * – 1 stop bit
frank26080115 0:bf7b9fba3924 162 * – No flow control
frank26080115 0:bf7b9fba3924 163 */
frank26080115 0:bf7b9fba3924 164 debug_frmwrk_init();
frank26080115 0:bf7b9fba3924 165
frank26080115 0:bf7b9fba3924 166 // print welcome screen
frank26080115 0:bf7b9fba3924 167 print_menu();
frank26080115 0:bf7b9fba3924 168
frank26080115 0:bf7b9fba3924 169 // initialize SSP configuration structure to default
frank26080115 0:bf7b9fba3924 170 SSP_ConfigStructInit(&SSP_ConfigStruct);
frank26080115 0:bf7b9fba3924 171 // Initialize SSP peripheral with parameter given in structure above
frank26080115 0:bf7b9fba3924 172 SSP_Init(LPC_SSP0, &SSP_ConfigStruct);
frank26080115 0:bf7b9fba3924 173
frank26080115 0:bf7b9fba3924 174 // Enable SSP peripheral
frank26080115 0:bf7b9fba3924 175 SSP_Cmd(LPC_SSP0, ENABLE);
frank26080115 0:bf7b9fba3924 176
frank26080115 0:bf7b9fba3924 177 _DBG_("Press '1' to start transfer...");
frank26080115 0:bf7b9fba3924 178 while (_DG != '1');
frank26080115 0:bf7b9fba3924 179
frank26080115 0:bf7b9fba3924 180 /* Initialize Buffer */
frank26080115 0:bf7b9fba3924 181 _DBG_("Init buffer");
frank26080115 0:bf7b9fba3924 182 Buffer_Init();
frank26080115 0:bf7b9fba3924 183
frank26080115 0:bf7b9fba3924 184 _DBG_("Start transfer...");
frank26080115 0:bf7b9fba3924 185
frank26080115 0:bf7b9fba3924 186 xferConfig.tx_data = Tx_Buf;
frank26080115 0:bf7b9fba3924 187 xferConfig.rx_data = Rx_Buf;
frank26080115 0:bf7b9fba3924 188 xferConfig.length = BUFFER_SIZE;
frank26080115 0:bf7b9fba3924 189 SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
frank26080115 0:bf7b9fba3924 190
frank26080115 0:bf7b9fba3924 191 // Verify buffer after transferring
frank26080115 0:bf7b9fba3924 192 Buffer_Verify();
frank26080115 0:bf7b9fba3924 193 _DBG_("Verify complete!");
frank26080115 0:bf7b9fba3924 194
frank26080115 0:bf7b9fba3924 195 /* Loop forever */
frank26080115 0:bf7b9fba3924 196 while(1);
frank26080115 0:bf7b9fba3924 197 return 1;
frank26080115 0:bf7b9fba3924 198 }
frank26080115 0:bf7b9fba3924 199
frank26080115 0:bf7b9fba3924 200 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 201 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 202 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 203 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 204 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 205 int main(void)
frank26080115 0:bf7b9fba3924 206 {
frank26080115 0:bf7b9fba3924 207 return c_entry();
frank26080115 0:bf7b9fba3924 208 }
frank26080115 0:bf7b9fba3924 209
frank26080115 0:bf7b9fba3924 210
frank26080115 0:bf7b9fba3924 211 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 212 /*******************************************************************************
frank26080115 0:bf7b9fba3924 213 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 214 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 215 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 216 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 217 * @return None
frank26080115 0:bf7b9fba3924 218 *******************************************************************************/
frank26080115 0:bf7b9fba3924 219 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 220 {
frank26080115 0:bf7b9fba3924 221 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 222 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 223
frank26080115 0:bf7b9fba3924 224 /* Infinite loop */
frank26080115 0:bf7b9fba3924 225 while(1);
frank26080115 0:bf7b9fba3924 226 }
frank26080115 0:bf7b9fba3924 227 #endif