We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hello friends,
i am using arm7 lpc2136 to make communication via SPI with a graphic lcd. for some reason this code is not working (SPI is not sending), i do not receive any error from the compiler keil-v5 however the microcontroller does not work.
XTAL=24MHZ
Main function:
#include "LPC213X.h" #include <stdint.h> #include "lcd.h" #define PIN021 21 extern void init_PLL(void); extern void init_gpiox(void); extern void SPI_init(void); //extern unsigned char SFEFlame[]; //extern unsigned char carita_feliz[]; extern void initlcd(void); void delay(void); int main(void) { int i; init_PLL(); init_gpiox(); SPI_init(); // initlcd(); delay(); while(1){ IOCLR0 |= 1UL<<PIN021; //Chip disable P0.21 delay(); IOSET0 |= 1UL<<PIN021; //Chip enable P0.21 delay(); S0SPDR ='A'; } //return 0; } void delay(void) { uint32_t i; for(i=0;i<=32000;i++); }
PLL function:
void init_PLL(void) { /*********************** ** ** CCLK = M * FOSC ** CCLK = FCCO / (2*P) ** ***********************/ // XTAL=24MHZ CCLK=48MHZ PLLCFG = 0x00000021; //M (bist[4:0]) = 1, P (bits [6:5])= 2; PLLCON = 0x00000001; //enable PLL PLLFEED = 0x000000AA; PLLFEED = 0x00000055; while (!(PLLSTAT & 0x00000400)); //Esperar hasta que el PLL este locked PLLCON = 0x00000003; //Conectar el PLL PLLFEED = 0x000000AA; //Actualizar registro de oscilador PLLFEED = 0x00000055; //VPBDIV = 0x00000002; // VLSI perifericos CCLK/2 = 12Mhz }
GPIO_config function:
void init_gpiox(void) { /* D/C PANTALLA LCD_TFT = GPIO1.31 ** CS PANTALLA LCD_TFT = GPIO1.26 ** RESET PANTALLA LCD_TFT = GPIO0.31 ** //IOSET0 |= (1<< DC_TFT); Para encender bit 26 ** //IOSET0 |= (1<< RESET_TFT); Para encender bit 31 *******************************************/ IO0PIN=0X00000000; IO0DIR=0XFFFFFFFF; //Puertos configurados como salidas // IODIR0 |= 0xffffffff; //Puertos configurados como salidas // IOSET0 = 0xffffffff; // IOCLR0 = 0xffffffff; //Puertos configurados salida en bajo IO1PIN=0X00000000; IO1DIR = 0xffffffff; //Puertos configurados como salidas // IOSET1 = 0xffffffff; // IOCLR1 = 0xffffffff; //Puertos configurados salida en bajo }
SPI0 function:
void SPI_init(void) { IO0PIN |=0x1500; //Habilitar funciones de SPI // IODIR0 |= 0X80; /* SSEL is output */ IOSET0 |=0X80; /* set SSEL to high */ S0SPCCR=200; //Setear maxima velocidad para SPI 48Mhz ---> 48khz S0SPCR=0x0824; //Seleccionar como master }
If the microcontroller itself does not work, that's a hardware fault.
Presumably, you really mean that your code is not producing the results that you wanted?
So the standard 3 questions are:
1. What, exactly, did you expect the code to do?
2. What, exactly, is the code actually doing?
3. What investigation / testing / debugging have you done to find the problem?
Hello Andrew, answering your questions, I have already confirmed the microcontroller with a simple application and responds well to changes in the input / output ports.
However, the function that stops the operation of the microcontroller is the function PLL when trying to use external oscillator the code does not work.
I have removed the PLL function in the code and I see the high and low changes in P0.21 however I do not see data output by the SPI.
Regards,