|
- void InitSPI(void)
- {
- SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
-
- GPIOPinConfigure(GPIO_PH4_SSI2CLK);
- //GPIOPinConfigure(GPIO_PH5_SSI2FSS);
- GPIOPinConfigure(GPIO_PH6_SSI2RX);
- GPIOPinConfigure(GPIO_PH7_SSI2TX);
-
- GPIOPinTypeSSI(GPIO_PORTH_BASE, GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_7);
-
- SSIConfigSetExpClk(SSI2_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,SSI_MODE_MASTER,2000000,16);
-
- SSIEnable(SSI2_BASE);
-
- while(SSIDataGetNonBlocking(SSI2_BASE, &buffer1)){}
- }
- void SPIRead(void)
- {
- SSIDataGet(SSI2_BASE, &buffer1);
- buffer1 &= 0x3FFF;
- buffer2 = buffer1;
- UARTprintf("Read: %x", buffer2);
- }
- //-----------------------------------------------------------------------------
- // Ö÷oˉêy:Ïòw25x80D′êy¾Y£¬Ö®oó¶á3ö¡£
- //-----------------------------------------------------------------------------
- int main(void)
- { tContext sContext;
- tRectangle sRect;
- char cThisChar;
- char ulIdx;
- SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_XTAL_16MHZ |
- SYSCTL_OSC_MAIN);
- //
- // 3õê¼»ˉ′®¿ú
- //
- lcd_ili932x_init(); //3õê¼»ˉLCDÇy¶ˉ
- GrContextInit(&sContext, &g_sLcdDisplay);//3õê¼»ˉí¼Dοa
- lcd_backlight_on();
- lcd_ili932x_flush(&sContext);
- sRect.sXMin = 0;
- sRect.sYMin = 0;
- sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1;
- sRect.sYMax = 23;
- GrContextForegroundSet(&sContext, ClrDarkBlue);
- GrRectFill(&sContext, &sRect); // ìî3äà¶é«·½¿é
- GrContextForegroundSet(&sContext, ClrWhite);
- GrRectDraw(&sContext, &sRect); // ¼ó°×é«¿ò¿ò
- GrContextFontSet(&sContext, &g_sFontCm20);
- GrStringDrawCentered(&sContext, "SPI Demo", -1,
- GrContextDpyWidthGet(&sContext) / 2, 10, 0); // ÏÔê¾êμÑé±êÖ¾
- InitConsole();//′®¿ú3õê¼»ˉ
- InitSPI();
- InitGPIO();
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // ê1ÄüLEDËùÔú¶Ë¿úPH
- GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_7); //ÅäÖÃPN.4ÎaledμÆêä3ö
- GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_7,GPIO_PIN_7);
- SysCtlDelay((SysCtlClockGet()/1)); // é趨ÿ′ÎÑóê±ê±¼ä£¬t=1 Ñóê±Îa1ms
- while(1){
- GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_7,0);
- UARTprintf("start /n");
- //GrStringDraw(&sContext,"SPI is Reading...", -1, 30, 80, 1); //′òó¡DÅÏ¢
- SPIRead();
- GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_7,GPIO_PIN_7);
- UARTprintf(" done /n");
- //GrContextFontSet(&sContext, &g_sFontCm20);//
- //sprintf(dis,"SPI Read: %x",buffer2);
- //GrStringDraw(&sContext,dis, -1, 30, 80, 1); //′òó¡DÅÏ¢
- }
- }
复制代码
|
|