static void prvSetupHardware( void ) { SystemCoreClockUpdate(); // enable clock to RAM1 LPC_SYSCON->SYSAHBCLKCTRL |= (1<<26); // init GPIO GPIOInit(); // init I2C I2CInit(I2CMASTER); //init ADC ADCInit(ADC_CLK); // init SPI ports SSP_IOConfig( 0 ); SSP_Init( 0 ); SSP_IOConfig( 1 ); SSP_Init( 1 ); // init keyboard CAP_KEY_Init(); // init MOSFET pin LPC_IOCON->PIO1_25=0x90; GPIOSetDir(PIN_MOSFET,1); }
//------------------------------------------------------------------------------ //! static HWStatus_t initSSP(void) //------------------------------------------------------------------------------ //@ brief initializes SSP interface for communication with sensor //------------------------------------------------------------------------------ static HWStatus_t initSSP(void) { SSPInit_t init; SSPStatus_t res=0; init.bitlen = t8_bit; init.clk_phase = 1; init.clk_pol = 1; init.mode = 0; init.frm_format = 0; init.loop_back=0; // init.ser_clk_rate = 9; //! 10 clocks per bit init.ser_clk_rate = 0; //! 1 clocks per bit init.clk_prescaler = 12; init.enable=1; res = SSP_Init(SSP_2, &init); if(res != SSP_ERR_OK) return HW_ERR_RESOURCE; ssp_init=1; return HW_ERR_OK; }
void SSP1_Initialize(void) //Slave { SSP_StructInit(&SSP1_InitStructure); SSP1_InitStructure.SSP_DataSize = SSP_DataSize_8b; SSP1_InitStructure.SSP_Mode = SSP_Mode_Slave; // SSP1 = Slave SSP_Init(SSP1,&SSP1_InitStructure); }
Spi::Spi(SerialCallback callback) : m_rq(SPI_RECEIVEBUF_SIZE), m_tq(SPI_TRANSMITBUF_SIZE, callback) { uint32_t i; volatile uint32_t d; SSP_CFG_Type configStruct; configStruct.CPHA = SSP_CPHA_FIRST; configStruct.CPOL = SSP_CPOL_HI; configStruct.ClockRate = 204000000; configStruct.Databit = SSP_DATABIT_16; configStruct.Mode = SSP_SLAVE_MODE; configStruct.FrameFormat = SSP_FRAME_SPI; // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP1, &configStruct); // clear receive fifo for (i=0; i<8; i++) d = LPC_SSP1->DR; // Enable SSP peripheral SSP_Cmd(LPC_SSP1, ENABLE); SSP_ClearIntPending(LPC_SSP1, SSP_INTCFG_RX); SSP_IntConfig(LPC_SSP1, SSP_INTCFG_RX, ENABLE); NVIC_SetPriority(SSP1_IRQn, 0); // high priority interrupt m_sync = false; m_recvCounter = 0; m_lastRecvCounter = 0; m_syncCounter = 0; setAutoSlaveSelect(false); }
/******************************************************************************* * Function Name : TP_Init * Description : TSC2046 Initialization * Input : None * Output : None * Return : None * Attention : None *******************************************************************************/ void TP_Init(void) { SSP_CFG_Type SSP_ConfigStruct; /* * Initialize SPI pin connect * P2.23 - TP_CS - used as GPIO * P2.22 - SCK * P2.26 - MISO * P2.27 - MOSI */ PINSEL_ConfigPin(2, 23, 0); PINSEL_ConfigPin(2, 22, 2); PINSEL_ConfigPin(2, 26, 2); PINSEL_ConfigPin(2, 27, 2); /* P0.16 CS is output */ GPIO_SetDir(TP_CS_PORT_NUM, (1<<TP_CS_PIN_NUM), 1); GPIO_SetValue(TP_CS_PORT_NUM, (1<<TP_CS_PIN_NUM)); PINSEL_ConfigPin(2, 11, 0); GPIO_SetDir(2, (1<<11), 0); /* P2.11 TP_INT is input */ /* initialize SSP configuration structure to default */ SSP_ConfigStructInit(&SSP_ConfigStruct); SSP_ConfigStruct.ClockRate = 250000; SSP_ConfigStruct.CPHA = SSP_CPHA_FIRST; //SSP_CPHA_SECOND SSP_CPHA_FIRST SSP_ConfigStruct.CPOL = SSP_CPOL_HI; //SSP_CPOL_LO SSP_CPOL_HI /* Initialize SSP peripheral with parameter given in structure above */ SSP_Init(LPC_SSP0, &SSP_ConfigStruct); /* Enable SSP peripheral */ SSP_Cmd(LPC_SSP0, ENABLE); }
void ads7843_init(void) { SSP_CFG_Type SSP_ConfigStruct; CONFIG_TS_PENIRQ; scu_pinmux(0x3,3,MD_PLN_FAST,FUNC2); // P3.3 connected to SCL/SCLK func2=SSP0 SCK0 // scu_pinmux(0x9,0,MD_PLN_FAST,FUNC7); // P9.0 connected to nCS func2=SSP0 SSEL0 scu_pinmux(0x9,0,MD_PLN_FAST | MD_EZI,FUNC0); GPIO_SetDir(4,1<<12,1); scu_pinmux(0x3,6,MD_PLN_FAST | MD_EZI,FUNC5); // P3.6 connected to SO func2=SSP0 MISO0 GPIO_SetDir(0,1<<6,0); scu_pinmux(0x3,7,MD_PLN_FAST ,FUNC5); // P3.7 connected to nSI func2=SSP0 MOSI0 // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); SSP_ConfigStruct.ClockRate = 100000; SSP_ConfigStruct.Databit = SSP_DATABIT_8; // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP0, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(LPC_SSP0, ENABLE); }
static void init_ssp(void) { SSP_CFG_Type SSP_ConfigStruct; PINSEL_CFG_Type PinCfg; /* * Initialize SPI pin connect * P0.7 - SCK; * P0.8 - MISO * P0.9 - MOSI * P2.2 - SSEL - used as GPIO */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); PinCfg.Funcnum = 0; PinCfg.Portnum = 2; PinCfg.Pinnum = 2; PINSEL_ConfigPin(&PinCfg); SSP_ConfigStructInit(&SSP_ConfigStruct); // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP1, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(LPC_SSP1, ENABLE); }
/*----------------------------------------------------------*\ | PCD5544 Initialize | \*----------------------------------------------------------*/ void LCD_Init(void) { //PINSEL0 &= 0xEFFFFFFF; // 设置SPI管脚连接 PINSEL0 |= 0x20000000; // 设置SPI管脚连接 //PINSEL1 &= 0xFFFFFCFF; // 设置SPI管脚连接 PINSEL1 |= 0x00000100; // 设置SPI管脚连接 IODIR |= (1<<21)|(1<<13)|(1<<19); IOCLR = (1<<19); //SSPCCR = 0x08; // 设置SPI时钟分频 //SSPCR = 0x38; // 设置SPI接口模式,MSTR=1,CPOL=1,CPHA=1,LSBF=0 SSP_Init(); IOSET=(1<<19); IOCLR=(1<<21); IOCLR=(1<<13); //准备写指令 /* LCD_Write(32+1); //进入扩展指令 LCD_Write(128+38); //设置Vop,相当于亮度 LCD_Write(4+3); //设置温度系数,相当于对比度 LCD_Write(16 +3); // 设置偏置,这句要与不要的实际效果好像一样 LCD_Write(32+0); //进入基本指令 LCD_Write(12); //使能芯片活动/垂直寻址 */ LCD_Write(0x21);//初始化Lcd,功能设定使用扩充指令 LCD_Write(0xd0);//设定液晶偏置电压 LCD_Write(0x20);//使用基本指令 LCD_Write(0x0C);//设定显示模式,正常显示 IOSET=(1<<21); Delay(1); }
//--------------------------------------------------------------------------------------- void SPI_Config() { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_Init(GPIO0, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIO1, &GPIO_InitStructure); GPIO_WriteBit(GPIO1, GPIO_Pin_10, Bit_SET); GPIO_WriteBit(GPIO0, GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7, Bit_SET); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_18 | GPIO_Pin_19; GPIO_Init(GPIO2, &GPIO_InitStructure); SSP_InitTypeDef SSP_InitStructure; SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; SSP_InitStructure.SSP_Mode = SSP_Mode_Master; SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; SSP_InitStructure.SSP_DataSize = SSP_DataSize_8b; SSP_InitStructure.SSP_NSS = SSP_NSS_Soft; SSP_InitStructure.SSP_ClockRate = 0; SSP_InitStructure.SSP_ClockPrescaler = 2; /* SSP baud rate : 30 MHz/(4*(2+1))= 2.5MHz */ SSP_Init(SSP0, &SSP_InitStructure); SSP_Cmd(SSP0, ENABLE); }
/*---------------------------------------------------------------------------- MAIN function *----------------------------------------------------------------------------*/ int main (void) { unsigned long status, current_tick, last_tick, i, j; unsigned char data[5]; unsigned char temp; // SysTick_Config(SystemCoreClock/1000); /* Generate IRQ each 1 ms */ init_mfrc500(); SER_init(); /* UART#1 Initialization */ SSP_IOConfig(); SSP_Init(); // init_eint(); printf("Welcome\r\n"); if(PcdReset() != MI_OK); { printf("PcdReset Fail\r\n"); while(1); } while(1); }
static void prvSetupHardware( void ) { SystemCoreClockUpdate(); // enable clock to RAM1 LPC_SYSCON->SYSAHBCLKCTRL |= (1<<26); // init GPIO GPIOInit(); // init I2C I2CInit(I2CMASTER); //init ADC ADCInit(ADC_CLK); // init SPI ports SSP_IOConfig( 0 ); SSP_Init( 0 ); SSP_IOConfig( 1 ); SSP_Init( 1 ); if (GPIOGetPinValue( PIN_CAL_DET )) { m_eAppCFGStatus = appANTENNA_CAL; // init CLKOUT pin LPC_IOCON->PIO0_1=1; // enable CLKOUT LPC_SYSCON->CLKOUTSEL=3; // select main clock LPC_SYSCON->CLKOUTUEN=1; // update clock source LPC_SYSCON->CLKOUTDIV=2; // divide by 2 } else { m_eAppCFGStatus = appNFC_KEYB_TEMP_SWITCH; // init keyboard CAP_KEY_Init(); // init MOSFET pin LPC_IOCON->PIO1_25=0x90; GPIOSetDir(PIN_MOSFET,1); } }
void SSP0_Initialize(void) //Master { SSP_StructInit(&SSP0_InitStructure); SSP0_InitStructure.SSP_FrameFormat = SSP_FrameFormat_MO; // Motorora SPI mode SSP0_InitStructure.SSP_DataSize = SSP_DataSize_8b; //SSP0_InitStructure.SSP_BaudRatePrescaler = SSP_BaudRatePrescaler_4; SSP_Init(SSP0,&SSP0_InitStructure); }
static void SpiInit(void) { // Init : SPI Enable, Master, Clock rate #if 0 #ifdef USE_RF12 // use clk/8 (2x 1/16th) to avoid exceeding RF12's SPI specs of 2.5 MHz when both are used together SPCR = _BV(SPE) | _BV(MSTR); #else SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR0); #endif SPSR |= _BV(SPI2X); #else // LPC17xx config PINSEL_CFG_Type pin_config = { .Portnum = DECODE_PORTNUM(SPI_SCK), .Pinmode = PINSEL_PINMODE_TRISTATE, .OpenDrain = PINSEL_PINMODE_NORMAL }; SSP_CFG_Type ssp_config = { .CPHA = SSP_CPHA_FIRST, .CPOL = SSP_CPOL_HI, .ClockRate = SSP_CLK, .Databit = SSP_DATABIT_8, .Mode = SSP_MASTER_MODE, .FrameFormat = SSP_FRAME_SPI }; // setup IO pins for SSP peripheral function pin_config.Funcnum = 2; // second alternate function pin_config.Pinnum = DECODE_BITNUM(SPI_MISO); PINSEL_ConfigPin(&pin_config); pin_config.Pinnum = DECODE_BITNUM(SPI_MOSI); PINSEL_ConfigPin(&pin_config); pin_config.Pinnum = DECODE_BITNUM(SPI_SCK); PINSEL_ConfigPin(&pin_config); pin_config.Funcnum = 0; // GPIO control pin_config.Pinnum = DECODE_BITNUM(SPI_SSEL); PINSEL_ConfigPin(&pin_config); // Initialize the SSP SSP_Init(SSP, &ssp_config); SSP_Cmd(SSP, ENABLE); #endif }
void glcd_init(void) { #if defined(GLCD_CONTROLLER_PCD8544) /* * Set up SPI (SSP) * Note: Max allowed SPI clock is 4 MHz from datasheet. */ /* Select SSP/SPI port */ SSP_IOConfig( CONTROLLER_SPI_PORT_NUMBER ); /* Initialise SSP/SPI port */ SSP_Init( CONTROLLER_SPI_PORT_NUMBER ); /* Above functions take care of SPI pins */ /* Set SS, DC and RST pins to output */ CONTROLLER_SS_PORT->DIR |= (1 << CONTROLLER_SS_PIN); CONTROLLER_DC_PORT->DIR |= (1 << CONTROLLER_DC_PIN); CONTROLLER_RST_PORT->DIR |= (1 << CONTROLLER_RST_PIN); /* Deselect LCD */ //GLCD_DESELECT(); /* Reset the display */ glcd_reset(); /* Get into the EXTENDED mode! */ glcd_command(PCD8544_FUNCTION_SET | PCD8544_EXTENDED_INSTRUCTION); /* LCD bias select (4 is optimal?) */ glcd_command(PCD8544_SET_BIAS | 0x2); /* Set VOP */ glcd_command(PCD8544_SET_VOP | 50); // Experimentally determined /* Back to standard instructions */ glcd_command(PCD8544_FUNCTION_SET); /* Normal mode */ glcd_command(PCD8544_DISPLAY_CONTROL | PCD8544_DISPLAY_NORMAL); glcd_select_screen(glcd_buffer,&glcd_bbox); glcd_clear(); #else /* GLCD_CONTROLLER_PCD8544 */ #error "Controller not supported by LPC111x" #endif }
void glcd_init(void) { #if defined(GLCD_CONTROLLER_PCD8544) // Set up SPI (SSP) // Note: Max allowed SPI clock is 4 MHz from datasheet. // select SSP/SPI port SSP_IOConfig( PCD8544_SPI_PORT_NUMBER ); // initialise SSP/SPI port SSP_Init( PCD8544_SPI_PORT_NUMBER ); // above functions take care of SPI pins // set SS, DC and RST pins to output PCD8544_SS_PORT->DIR |= (1 << PCD8544_SS_PIN); PCD8544_DC_PORT->DIR |= (1 << PCD8544_DC_PIN); PCD8544_RST_PORT->DIR |= (1 << PCD8544_RST_PIN); // deselect LCD //GLCD_DESELECT(); // reset the display glcd_reset(); // get into the EXTENDED mode! glcd_command(PCD8544_FUNCTION_SET | PCD8544_EXTENDED_INSTRUCTION); // LCD bias select (4 is optimal?) glcd_command(PCD8544_SET_BIAS | 0x2); // set VOP glcd_command(PCD8544_SET_VOP | 50); // Experimentally determined // back to standard instructions glcd_command(PCD8544_FUNCTION_SET); // normal mode glcd_command(PCD8544_DISPLAY_CONTROL | PCD8544_DISPLAY_NORMAL); glcd_select_screen((uint8_t *)&glcd_buffer,&glcd_bbox); glcd_clear(); #else /* GLCD_CONTROLLER_PCD8544 */ #error Controller not supported. #endif }
void LED_init(){ //TODO lsb first spi mode 0 0? GPIO_SetDir(LED_OE_PORT, LED_OE_BIT, 1); GPIO_SetValue(LED_OE_PORT, LED_OE_BIT); GPIO_SetDir(LED_LE_PORT, LED_LE_BIT, 1); GPIO_SetValue(LED_LE_PORT, LED_LE_BIT); GPIO_SetDir(WF_HIBERNATE_PORT, WF_HIBERNATE_BIT, 0); GPIO_SetValu(WF_HIBERNATE_PORT, WF_HIBERNATE_BIT); // Initialize SPI pin connect PINSEL_CFG_Type PinCfg; SSP_CFG_Type SSP_ConfigStruct; /* SCK1 */ PinCfg.Funcnum = PINSEL_FUNC_2; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLDOWN; PinCfg.Pinnum = LED_SCK_PIN; PinCfg.Portnum = LED_SCK_PORT; PINSEL_ConfigPin(&PinCfg); /* MISO1 */ PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinCfg.Pinnum = LED_MISO_PIN; PinCfg.Portnum = LED_MISO_PORT; PINSEL_ConfigPin(&PinCfg); /* MOSI1 */ PinCfg.Pinnum = LED_MOSI_PIN; PinCfg.Portnum = LED_MOSI_PORT; PINSEL_ConfigPin(&PinCfg); /* initialize SSP configuration structure */ SSP_ConfigStruct.CPHA = SSP_CPHA_FIRST; SSP_ConfigStruct.CPOL = SSP_CPOL_HI; SSP_ConfigStruct.ClockRate = 10000000; /* TLC5927 max freq = 30Mhz */ SSP_ConfigStruct.Databit = SSP_DATABIT_16; SSP_ConfigStruct.Mode = SSP_MASTER_MODE; SSP_ConfigStruct.FrameFormat = SSP_FRAME_SPI; SSP_Init(LPC_SSP0, &SSP_ConfigStruct); RIT_Init(LPC_RIT); RIT_TimerConfig(LPC_RIT, TIME_INTERVAL); //TODO: decide on time interval NVIC_SetPriority(LPC_RIT, 0); // set according to main.c NVIC_EnableIRQ(LPC_RIT); /* Enable SSP peripheral */ SSP_Cmd(LPC_SSP0, ENABLE); }
void spi_init() { uint32_t i; volatile uint32_t d; SSP_CFG_Type configStruct; g_receive.m_buf = new uint16_t[SPI_RECEIVEBUF_SIZE]; g_receive.m_read = 0; g_receive.m_write = 0; g_receive.m_produced = 0; g_receive.m_consumed = 0; g_transmit.m_buf = new uint16_t[SPI_TRANSMITBUF_SIZE]; g_transmit.m_read = 0; g_transmit.m_len = 0; g_transmit.m_callback = (TransmitCallback)NULL; configStruct.CPHA = SSP_CPHA_FIRST; configStruct.CPOL = SSP_CPOL_HI; configStruct.ClockRate = 204000000; configStruct.Databit = SSP_DATABIT_16; configStruct.Mode = SSP_SLAVE_MODE; configStruct.FrameFormat = SSP_FRAME_SPI; // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP1, &configStruct); // clear receive fifo for (i=0; i<8; i++) d = LPC_SSP1->DR; // Enable SSP peripheral SSP_Cmd(LPC_SSP1, ENABLE); SSP_ClearIntPending(LPC_SSP1, SSP_INTCFG_RT); SSP_IntConfig(LPC_SSP1, SSP_INTCFG_RT, ENABLE); // sync spi_sync(); // enable interrupt NVIC_SetPriority(SSP1_IRQn, 0); // high priority interrupt NVIC_EnableIRQ(SSP1_IRQn); }
void SPI1_Int(void) { PINSEL_ConfigPin(0, 7, 2);//p0.7:SSP0_SCK PINSEL_ConfigPin(0, 6, 2);//p0.6: CS //SSP0_SSEL PINSEL_ConfigPin(0, 8, 2);//p0.8: SSP0_MISO PINSEL_ConfigPin(0, 9, 2);//p0.9: SSP0_MOSI SSP_ConfigStruct.CPHA = SSP_CPHA_FIRST;//SSP控制寄存器在帧传输的第一个时钟跳变沿捕获串行数据 SSP_ConfigStruct.CPOL = SSP_CPOL_HI;//SSP控制器使总线时钟在每帧数据传输之间保持高电平 SSP_ConfigStruct.ClockRate = 1000000;// SSP_ConfigStruct.Databit = SSP_DATABIT_8;//每帧8位数据 SSP_ConfigStruct.Mode = SSP_SLAVE_MODE;//选择SSP为从机 SSP_ConfigStruct.FrameFormat = SSP_FRAME_SPI;//SPI 模式 SSP_Init(LPC_SSP1, &SSP_ConfigStruct);// Initialize SSP peripheral with parameter given in structure above LPC_SSP1->CR1 |= SSP_CR1_SSP_EN;//SSP_Cmd(0, ENABLE);// Enable SSP peripheral printf("\n\rSPI_INIT\n\r"); }
//-----------------------------------------------------------------// // Setup SSP module // HCLK = 32 MHz // The information rate is computed using the following formula: // F_SSPCLK / ( CPSDVR * (1 + SCR) ) // 3.2 MHz //-----------------------------------------------------------------// void HW_SSPInit(void) { SSP_InitTypeDef sSSP; SSP_StructInit (&sSSP); SSP_BRGInit(MDR_SSP2,SSP_HCLKdiv1); // F_SSPCLK = HCLK / 1 sSSP.SSP_SCR = 0x04; // 0 to 255 sSSP.SSP_CPSDVSR = 2; // even 2 to 254 sSSP.SSP_Mode = SSP_ModeMaster; sSSP.SSP_WordLength = SSP_WordLength9b; sSSP.SSP_SPH = SSP_SPH_1Edge; sSSP.SSP_SPO = SSP_SPO_Low; sSSP.SSP_FRF = SSP_FRF_SPI_Motorola; sSSP.SSP_HardwareFlowControl = SSP_HardwareFlowControl_SSE; SSP_Init (MDR_SSP2,&sSSP); SSP_Cmd(MDR_SSP2, ENABLE); }
/******************************************************************************* * Function Name : Lcd_Configuration * Description : Configures LCD Control lines * Input : None * Output : None * Return : None * Attention : None *******************************************************************************/ static void LCD_Configuration(void) { PINSEL_CFG_Type PinCfg; SSP_CFG_Type SSP_ConfigStruct; /* * Initialize SPI pin connect * P0.15 - LCD_CSB - used as GPIO * P0.16 - LCD_SCK * P0.17 - LCD_MISO * P0.18 - LCD_MOSI */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Funcnum = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 16; PINSEL_ConfigPin(&PinCfg); /* P1.31 LCD_CSB is output */ GPIO_SetDir(CSB_PORT_NUM, ( (uint32_t) 1 << CSB_PIN_NUM ), 1); GPIO_SetValue(CSB_PORT_NUM, ( (uint32_t) 1 << CSB_PIN_NUM ) ); /* initialize SSP configuration structure to default */ SSP_ConfigStructInit(&SSP_ConfigStruct); SSP_ConfigStruct.CPHA = SSP_CPHA_SECOND; SSP_ConfigStruct.CPOL = SSP_CPOL_LO; SSP_ConfigStruct.ClockRate = 34000000; /* Initialize SSP peripheral with parameter given in structure above */ SSP_Init(LPC_SSP0, &SSP_ConfigStruct); /* Enable SSP peripheral */ SSP_Cmd(LPC_SSP0, ENABLE); }
SPI::SPI(PinName mosi, PinName miso, PinName sclk, const char *name) : _mosi(-1), _miso(-1), _sclk(-1), _bits(8), _hz(1000000), _mode(0), _delay(0) { _name = (char *) name; // ハードSPIのみをサポート(ピン固定) if (mosi == MOSI && (miso == MISO || miso == NC) && sclk == SCKL) { _spi = LPC_SSP0; SSP_IOConfig(SSP_NUM); /* initialize SSP port, share pins with SPI1 on port2(p2.0-3). */ SSP_Init(SSP_NUM); // 8bits, mode=0; format(_bits, _mode); // 1MHz frequency(_hz); // バッファの初期化(例題に習った) for (int i = 0; i < SSP_BUFSIZE; i++) { src_addr[i] = 0; dst_addr[i] = 0; } } }
int main(void) { volatile int timeKeeper=0; unsigned char i=0; SSP_CFG_Type sspChannelConfig; SSP_DATA_SETUP_Type sspDataConfig; uint8_t rxBuff[5]; uint8_t txBuff[5]; LPC_PINCON->PINSEL0 |= 0x2<<14; //SCK1 LPC_PINCON->PINSEL0 |= 0x2<<18; //MOSI1 PORT_CS->FIODIR |= 1<<2; //P2.2 as CSn sspDataConfig.length = 1; sspDataConfig.tx_data = txBuff; sspDataConfig.rx_data = rxBuff; SSP_ConfigStructInit(&sspChannelConfig); SSP_Init(SSP_CHANNEL, &sspChannelConfig); SSP_Cmd(SSP_CHANNEL, ENABLE); while(1) { if (timeKeeper++ % 500000 == 0) { PORT_CS->FIOCLR |= PIN_MASK_CS; //CS low txBuff[0] = segmentLUT[i++]; //Buffer next numeral //Only display 0-9 if (i==10) i=0; //Transfer to 7-Segment Display Driver SSP_ReadWrite(SSP_CHANNEL, &sspDataConfig, SSP_TRANSFER_POLLING); PORT_CS->FIOSET |= PIN_MASK_CS; //CS High } } return 0 ; }
void spi_init (int spi_channel) { SSP_CFG_Type SSP_ConfigStruct; if (spi_channel == 0) pSPI = LPC_SSP0; else pSPI = LPC_SSP1; /* initialize SSP configuration structure */ SSP_ConfigStruct.CPHA = SSP_CPHA_FIRST; SSP_ConfigStruct.CPOL = SSP_CPOL_HI; SSP_ConfigStruct.ClockRate = 200000; /* 200KHz */ SSP_ConfigStruct.Databit = SSP_DATABIT_8; SSP_ConfigStruct.Mode = SSP_MASTER_MODE; SSP_ConfigStruct.FrameFormat = SSP_FRAME_SPI; SSP_Init(pSPI, &SSP_ConfigStruct); /* Enable SSP peripheral */ SSP_Cmd(pSPI, ENABLE); }
/******************************************************************************* * Function Name : SPI_FLASH_Init * Description : SPI FLASH Configuration * Input : None * Output : None * Return : None * Attention : None *******************************************************************************/ void SPI_FLASH_RTC_Init(void) { SSP_CFG_Type SSP_ConfigStruct; /* * Initialize SPI pin connect * P2.19 - SSEL - used as GPIO * P2.22 - SCK * P2.26 - MISO * P2.27 - MOSI */ PINSEL_ConfigPin(FLASH_CS_PORT_NUM, FLASH_CS_PIN_NUM, 0); /* P2.19 - GPIO */ // PINSEL_ConfigPin(RTC_CS_PORT_NUM, RTC_CS_PIN_NUM, 0); /* P2.21 - GPIO */ PINSEL_ConfigPin(RTC_FLASH_MOSI_PORT_NUM, RTC_FLASH_MOSI_PIN_NUM, RTC_FLASH_MOSI_FUN_NUM); /* SSP0_SCK */ PINSEL_ConfigPin(RTC_FLASH_MISO_PORT_NUM, RTC_FLASH_MISO_PIN_NUM, RTC_FLASH_MISO_FUN_NUM); /* SSP0_MISO */ PINSEL_ConfigPin(RTC_FLASH_SCK_PORT_NUM, RTC_FLASH_SCK_PIN_NUM, RTC_FLASH_SCK_FUN_NUM); /* SSP0_MOSI */ PINSEL_SetPinMode(RTC_FLASH_MOSI_PORT_NUM,RTC_FLASH_MOSI_PIN_NUM,IOCON_MODE_PULLUP); PINSEL_SetPinMode(RTC_FLASH_MISO_PORT_NUM,RTC_FLASH_MISO_PIN_NUM,IOCON_MODE_PLAIN); /* P2.19 CS is output */ GPIO_SetDir(FLASH_CS_PORT_NUM, (1<<FLASH_CS_PIN_NUM), 1); SPI_FLASH_CS_HIGH(); /* P2.21 CS is output */ // GPIO_SetDir(RTC_CS_PORT_NUM, (1<<RTC_CS_PIN_NUM), 1); // SPI_RTC_CS_HIGH(); /* initialize SSP configuration structure to default */ SSP_ConfigStructInit(&SSP_ConfigStruct); SSP_ConfigStruct.CPHA = SSP_CPHA_FIRST; SSP_ConfigStruct.CPOL = SSP_CPOL_HI; //SSP_ConfigStruct.FrameFormat = SSP_FRAME_TI; //SSP_ConfigStruct.Databit = SSP_DATABIT_8; /* Initialize SSP peripheral with parameter given in structure above */ SSP_ConfigStruct.ClockRate = 3000000; //SSP_ConfigStruct.Mode = SSP_MASTER_MODE; SSP_Init(RTC_FLASH_SSP, &SSP_ConfigStruct); /* Enable SSP peripheral */ SSP_Cmd(RTC_FLASH_SSP, ENABLE); }
void ssp_spi_init(){ SSP_CFG_Type SSP_ConfigStruct; PINSEL_CFG_Type PinCfg; SSP_ConfigStructInit(&SSP_ConfigStruct); /* * Initialize SPI pin connect * P0.7 - SCK; * P0.6 - SSEL * P0.8 - MISO * P0.9 - MOSI */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); LPC_PINCON->PINSEL0 &= ~(0x3<<12); // [P0.6] SSEL1 as GPIO. auto ssp does not work because it toggles cs between bytes. LPC_GPIO0->FIODIR |= (1 << SPI_SCK_PIN) | (1 << SPI_MOSI_PIN) | (1 << SPI_SSEL_PIN); LPC_GPIO0->FIODIR &= ~(1 << SPI_MISO_PIN); LPC_GPIO0->FIOSET |= PIN_MASK_CS; // - set high SSP_Init(LPC_SSP1,&SSP_ConfigStruct); SSP_Cmd(LPC_SSP1, ENABLE); }
/** * @brief Main Function */ int main() { /* Set Systme init */ SystemInit(); // *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz /* CLK OUT Set */ // PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function /* < SSP_StructInit default values SSP_InitStructure.SSP_SerialClockRate = 0x00; SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_MO; SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; SSP_InitStructure.SSP_DataSize = SSP_DataSize_8b; SSP_InitStructure.SSP_SOD = SSP_SOD_RESET; SSP_InitStructure.SSP_Mode = SSP_Mode_Master; SSP_InitStructure.SSP_NSS = SSP_NSS_Hard; SSP_InitStructure.SSP_LBM = SSP_LBM_RESET; SSP_InitStructure.SSP_SSE = SSP_SSE_SET; SSP_InitStructure.SSP_BaudRatePrescaler = SSP_BaudRatePrescaler_2; */ /* SSP0 Init -- SSP Master */ SSP_StructInit(&SSP0_InitStructure); SSP0_InitStructure.SSP_FrameFormat = SSP_FrameFormat_MO; // Motorora SPI mode SSP0_InitStructure.SSP_DataSize = SSP_DataSize_16b; SSP_Init(SSP0,&SSP0_InitStructure); /* SSP1 Init -- SSP Slave */ SSP_StructInit(&SSP1_InitStructure); SSP1_InitStructure.SSP_DataSize = SSP_DataSize_16b; SSP1_InitStructure.SSP_Mode = SSP_Mode_Slave; // SSP1 = Slave SSP_Init(SSP1,&SSP1_InitStructure); /* GPIO LED(R) Setting */ GPIO_InitDef.GPIO_Pin = GPIO_Pin_8; // Connecting GPIO_Pin_8(LED(R)) GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; // Set to GPIO Mode to Output Port GPIO_Init(GPIOC, &GPIO_InitDef); // Set to GPIOC PAD_AFConfig(PAD_PC,GPIO_Pin_8, PAD_AF1); // PAD Config - LED used 2nd Function /* GPIO LED(G) Setting */ GPIO_InitDef.GPIO_Pin = GPIO_Pin_9; // Connecting GPIO_Pin_9(LED(G)) GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; // Set to GPIO Mode to Output Port GPIO_Init(GPIOC, &GPIO_InitDef); // Set to GPIOC PAD_AFConfig(PAD_PC,GPIO_Pin_9, PAD_AF1); // PAD Config - LED used 2nd Function GPIO_SetBits(GPIOC, GPIO_Pin_8); // LED red off GPIO_SetBits(GPIOC, GPIO_Pin_9); // LED green off /* Send only data to SSP1 */ for (TxIdx=0; TxIdx<BufferSize; TxIdx++) { SSP_SendData(SSP0, SSP0_Buffer_Tx[TxIdx]); while( SSP_GetFlagStatus(SSP0, SSP_FLAG_BSY) ); } /* Receive only data from SSP0 */ while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RNE)) { SSP1_Buffer_Rx[RxIdx] = (uint16_t)SSP_ReceiveData(SSP1); RxIdx++; } /* Check the received data with the send ones */ TransferStatus = Buffercmp(SSP0_Buffer_Tx, SSP1_Buffer_Rx, BufferSize); /* TransferStatus = PASSED, if the data transmitted and received are correct */ /* TransferStatus = FAILED, if the data transmitted and received are different */ if(TransferStatus == PASSED) { GPIO_ResetBits(GPIOC, GPIO_Pin_9); //Received are correct == LED green On } else if(TransferStatus == FAILED) { GPIO_ResetBits(GPIOC, GPIO_Pin_8); //Received are different == LED red On } }
/* SSP_LoopBack function */ void SSP_LoopBack(void) { SSP_InitTypeDef initSSP; SSP_FIFOState fifoState; uint16_t datTx = 0U; /* must use 16bit type */ uint32_t cntTx = 0U; uint32_t cntRx = 0U; uint16_t receive = 0U; uint16_t Rx_Buf[MAX_BUFSIZE] = { 0U }; uint16_t Tx_Buf[MAX_BUFSIZE] = { 0U }; SystemInit(); /* enable the LED on board to display some info */ UART_Configuration(UART); UART_Print(UART, "This is an example for SSP module!\n\r"); /* configure the SSP module */ initSSP.FrameFormat = SSP_FORMAT_SPI; /* default is to run at maximum bit rate */ initSSP.PreScale = 2U; initSSP.ClkRate = 1U; /* define BITRATE_MIN to run at minimum bit rate */ /* BitRate = fSYS / (PreScale x (1 + ClkRate)) */ #ifdef BITRATE_MIN initSSP.PreScale = 254U; initSSP.ClkRate = 255U; #endif initSSP.ClkPolarity = SSP_POLARITY_LOW; initSSP.ClkPhase = SSP_PHASE_FIRST_EDGE; initSSP.DataSize = 16U; initSSP.Mode = SSP_MASTER; SSP_Init(&initSSP); /* enable loop back mode for self test */ SSP_SetLoopBackMode(ENABLE); /* enable and run SSP module */ SSP_Enable(); while (1) { datTx++; /* send data if Tx FIFO is available */ fifoState = SSP_GetFIFOState(SSP_TX); if ((fifoState == SSP_FIFO_EMPTY) || (fifoState == SSP_FIFO_NORMAL)) { SSP_SetTxData(datTx); if (cntTx < MAX_BUFSIZE) { Tx_Buf[cntTx] = datTx; cntTx++; } else { /* do nothing */ } } else { /* do nothing */ } /* check if there is data arrived */ fifoState = SSP_GetFIFOState(SSP_RX); if ((fifoState == SSP_FIFO_FULL) || (fifoState == SSP_FIFO_NORMAL)) { receive = SSP_GetRxData(); if (cntRx < MAX_BUFSIZE) { Rx_Buf[cntRx] = receive; cntRx++; } else { /* Place a break point here to check if receive data is right. */ /* Success Criteria: */ /* Every data transmited from Tx_Buf is received in Rx_Buf. */ /* When the line "#define BITRATE_MIN" is commented, the SSP is run in maxium */ /* bit rate, so we can find there is enough time to transmit date from 1 to */ /* MAX_BUFSIZE one by one. but if we uncomment that line, SSP is run in */ /* minimum bit rate, we will find that receive data can't catch "datTx++", */ /* in this so slow bit rate, when the Tx FIFO is available, the cntTx has */ /* been increased so much. */ __NOP(); } } else { /* do nothing */ } sprintf(message, "Received data is %d\n\r" + (uint8_t)(receive / 8000)); UART_Print(UART, message); } }
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) { SSP_InitTypeDef config; // Check pin parameters SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI); SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO); SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK); SPIName spi_ssel = (SPIName)pinmap_peripheral(ssel, PinMap_SPI_SSEL); SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); obj->module = (SPIName)pinmap_merge(spi_data, spi_sclk); obj->module = (SPIName)pinmap_merge(spi_data, spi_cntl); MBED_ASSERT((int)obj->module!= NC); // Identify SPI module to use switch ((int)obj->module) { case SPI_0: obj->spi = TSB_SSP0; break; case SPI_1: obj->spi = TSB_SSP1; break; case SPI_2: obj->spi = TSB_SSP2; break; default: obj->spi= NULL; obj->module = (SPIName)NC; error("Cannot found SPI module corresponding with input pins."); break; } // pin out the spi pins pinmap_pinout(mosi, PinMap_SPI_MOSI); pinmap_pinout(miso, PinMap_SPI_MISO); pinmap_pinout(sclk, PinMap_SPI_SCLK); if (ssel != NC) { pinmap_pinout(ssel, PinMap_SPI_SSEL); } // Declare Config config.FrameFormat = SSP_FORMAT_SPI; // bit_rate = Fsys / (clk_prescale * (clk_rate + 1)) config.PreScale = 48; config.ClkRate = 0; config.ClkPolarity = SSP_POLARITY_LOW; config.ClkPhase = SSP_PHASE_FIRST_EDGE; config.DataSize = 0x08; obj->bits = config.DataSize; config.Mode = SSP_MASTER; SSP_Init(obj->spi, &config); // Disable all interrupt SSP_SetINTConfig(obj->spi, SSP_INTCFG_NONE); SSP_Enable(obj->spi); }
/*********************************************************************//** * @brief Main SSP program body **********************************************************************/ int c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; PINSEL_CFG_Type PinCfg; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif /* * Initialize SPI pin connect * P0.15 - SCK; * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PINSEL_ConfigPin(&PinCfg); /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Initializing SSP device section ------------------------------------------------------ */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP0, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(LPC_SSP0, ENABLE); /* GPDMA Interrupt configuration section ------------------------------------------------- */ /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Initializing Buffer section ----------------------------------------------------------- */ Buffer_Init(); /* Initialize GPDMA controller */ GPDMA_Init(); /* Setting GPDMA interrupt */ // Disable interrupt for DMA NVIC_DisableIRQ (DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Configure GPDMA channel 0 -------------------------------------------------------------*/ /* DMA Channel 0 */ GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = (uint32_t) &dma_src; // Destination memory - Not used GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = sizeof(dma_src); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = GPDMA_CONN_SSP0_Tx; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback0); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Configure GPDMA channel 1 -------------------------------------------------------------*/ /* DMA Channel 1 */ GPDMACfg.ChannelNum = 1; // Source memory - not used GPDMACfg.SrcMemAddr = 0; // Destination memory - Not used GPDMACfg.DstMemAddr = (uint32_t) &dma_dst; // Transfer size GPDMACfg.TransferSize = sizeof(dma_dst); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_SSP0_Rx; // Destination connection - not used GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback1); /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; _DBG_("Start transfer..."); // Enable Tx and Rx DMA on SSP0 SSP_DMACmd (LPC_SSP0, SSP_DMA_RX, ENABLE); SSP_DMACmd (LPC_SSP0, SSP_DMA_TX, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(1, ENABLE); // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); /* Wait for GPDMA processing complete */ while (((Channel0_TC == 0) && (Channel0_Err == 0)) \ || ((Channel1_TC == 0) && (Channel1_Err ==0))); /* Verify buffer */ Buffer_Verify(); _DBG_("Verify complete!"); /* Loop forever */ while(1); return 1; }
void main(void) #endif { RST_CLK_DeInit(); RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0); /* Enable peripheral clocks --------------------------------------------------*/ RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_SSP1 | RST_CLK_PCLK_SSP2 | RST_CLK_PCLK_DMA),ENABLE); RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTF | RST_CLK_PCLK_PORTD), ENABLE); /* Init NVIC */ SCB->AIRCR = 0x05FA0000 | ((uint32_t)0x500); SCB->VTOR = 0x08000000; /* Disable all interrupt */ NVIC->ICPR[0] = 0xFFFFFFFF; NVIC->ICER[0] = 0xFFFFFFFF; /* Disable all DMA request */ MDR_DMA->CHNL_REQ_MASK_CLR = 0xFFFFFFFF; MDR_DMA->CHNL_USEBURST_CLR = 0xFFFFFFFF; /* Reset PORTD settings */ PORT_DeInit(MDR_PORTD); /* Reset PORTF settings */ PORT_DeInit(MDR_PORTF); /* Configure SSP2 pins: FSS, CLK, RXD, TXD */ /* Configure PORTD pins 2, 3, 5, 6 */ PORT_InitStructure.PORT_Pin = (PORT_Pin_2 | PORT_Pin_3 | PORT_Pin_5); PORT_InitStructure.PORT_OE = PORT_OE_IN; PORT_InitStructure.PORT_FUNC = PORT_FUNC_ALTER; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_SPEED = PORT_SPEED_FAST; PORT_Init(MDR_PORTD, &PORT_InitStructure); PORT_InitStructure.PORT_OE = PORT_OE_OUT; PORT_InitStructure.PORT_Pin = (PORT_Pin_6); PORT_Init(MDR_PORTD, &PORT_InitStructure); /* Configure SSP1 pins: FSS, CLK, RXD, TXD */ /* Configure PORTF pins 0, 1, 2, 3 */ PORT_InitStructure.PORT_Pin = (PORT_Pin_3); PORT_InitStructure.PORT_OE = PORT_OE_IN; PORT_Init(MDR_PORTF, &PORT_InitStructure); PORT_InitStructure.PORT_Pin = (PORT_Pin_0 | PORT_Pin_1 | PORT_Pin_2); PORT_InitStructure.PORT_OE = PORT_OE_OUT; PORT_Init(MDR_PORTF, &PORT_InitStructure); /* Init RAM */ Init_RAM (DstBuf1, BufferSize); Init_RAM (SrcBuf1, BufferSize); Init_RAM (DstBuf2, BufferSize); Init_RAM (SrcBuf2, BufferSize); /* Reset all SSP settings */ SSP_DeInit(MDR_SSP1); SSP_DeInit(MDR_SSP2); SSP_BRGInit(MDR_SSP1,SSP_HCLKdiv16); SSP_BRGInit(MDR_SSP2,SSP_HCLKdiv16); /* SSP1 MASTER configuration ------------------------------------------------*/ SSP_StructInit (&sSSP); sSSP.SSP_SCR = 0x10; sSSP.SSP_CPSDVSR = 2; sSSP.SSP_Mode = SSP_ModeMaster; sSSP.SSP_WordLength = SSP_WordLength16b; sSSP.SSP_SPH = SSP_SPH_1Edge; sSSP.SSP_SPO = SSP_SPO_Low; sSSP.SSP_FRF = SSP_FRF_SPI_Motorola; sSSP.SSP_HardwareFlowControl = SSP_HardwareFlowControl_SSE; SSP_Init (MDR_SSP1,&sSSP); /* SSP2 SLAVE configuration ------------------------------------------------*/ sSSP.SSP_SPH = SSP_SPH_1Edge; sSSP.SSP_SPO = SSP_SPO_Low; sSSP.SSP_CPSDVSR = 12; sSSP.SSP_Mode = SSP_ModeSlave; SSP_Init (MDR_SSP2,&sSSP); /* Enable SSP1 DMA Rx and Tx request */ SSP_DMACmd(MDR_SSP1,(SSP_DMA_RXE | SSP_DMA_TXE), ENABLE); /* Enable SSP2 DMA Rx and Tx request */ SSP_DMACmd(MDR_SSP2,(SSP_DMA_RXE | SSP_DMA_TXE), ENABLE); /* Reset all DMA settings */ DMA_DeInit(); DMA_StructInit(&DMA_InitStr); /* DMA_Channel_SSP1_RX configuration ---------------------------------*/ /* Set Primary Control Data */ DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)(&(MDR_SSP1->DR)); DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)DstBuf1; DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncNo; DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncHalfword; DMA_PriCtrlStr.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_PriCtrlStr.DMA_Mode = DMA_Mode_Basic; DMA_PriCtrlStr.DMA_CycleSize = BufferSize; DMA_PriCtrlStr.DMA_NumContinuous = DMA_Transfers_4; DMA_PriCtrlStr.DMA_SourceProtCtrl = DMA_SourcePrivileged; DMA_PriCtrlStr.DMA_DestProtCtrl = DMA_DestPrivileged; /* Set Channel Structure */ DMA_InitStr.DMA_PriCtrlData = &DMA_PriCtrlStr; DMA_InitStr.DMA_Priority = DMA_Priority_High; DMA_InitStr.DMA_UseBurst = DMA_BurstClear; DMA_InitStr.DMA_SelectDataStructure = DMA_CTRL_DATA_PRIMARY; /* Init DMA channel */ DMA_Init(DMA_Channel_SSP1_RX, &DMA_InitStr); /* DMA_Channel_SSP2_RX configuration ---------------------------------*/ /* Set Primary Control Data */ DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)(&(MDR_SSP2->DR)); DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)DstBuf2; /* Init DMA channel */ DMA_Init(DMA_Channel_SSP2_RX, &DMA_InitStr); /* DMA_Channel_SSP1_TX configuration ---------------------------------*/ /* Set Primary Control Data */ DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)SrcBuf1; DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)(&(MDR_SSP1->DR)); DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncHalfword; DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncNo; DMA_InitStr.DMA_Priority = DMA_Priority_Default; /* Init DMA channel */ DMA_Init(DMA_Channel_SSP1_TX, &DMA_InitStr); /* DMA_Channel_SSP2_TX configuration ---------------------------------*/ /* Set Primary Control Data */ DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)SrcBuf2; DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)(&(MDR_SSP2->DR)); /* Init DMA channel */ DMA_Init(DMA_Channel_SSP2_TX, &DMA_InitStr); /* Enable SSP1 */ SSP_Cmd(MDR_SSP1, ENABLE); /* Enable SSP2 */ SSP_Cmd(MDR_SSP2, ENABLE); /* Transfer complete */ while((SSP_GetFlagStatus(MDR_SSP1, SSP_FLAG_BSY))) { } while((SSP_GetFlagStatus(MDR_SSP2, SSP_FLAG_BSY))) { } /* Check the corectness of written dada */ TransferStatus1 = Verif_mem ((BufferSize), SrcBuf1, DstBuf2); TransferStatus2 = Verif_mem ((BufferSize), SrcBuf2, DstBuf1); /* TransferStatus1, TransferStatus2 = PASSED, if the data transmitted and received are correct */ /* TransferStatus1, TransferStatus2 = FAILED, if the data transmitted and received are different */ while(1) { } }