lpcware

UART communication between avr butterfly and lpc1769

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by andygook on Wed Apr 11 23:07:46 MST 2012
I have a problem with the reception of data in the lpc, seems not to read the received data, and do not know if I have something wrong with the code. not use rs232 and be cross-connect the microcontroller on pin 9 and 10 psi.
someone who can help in this situation?

//AVR CODE

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/delay.h>
#include <inttypes.h>


#include "mydefs.h"
#include "LCD_functions.h"
#include "LCD_driver.h"
#include "button.h"
#include "usart.h"



int main(void)
{   
    PGM_P statetext = PSTR("MICROCONTROLADORES AVANZADOS");
   uint8_t input;
      char *cadena;
   int  i;
     
  // Disable Analog Comparator (power save)
    ACSR = (1<<ACD);
  
   // Disable Digital input on PF0-2 (power save)
    DIDR0 = (7<<ADC0D);

   // Enable pullups
   PORTB = (15<<PB0);      
   PORTE = (15<<PE4);
  
    Button_Init();              // Initialize pin change interrupt on    joystick
  
    LCD_Init();                 // initialize the LCD

   CLKPR = (1<<CLKPCE);        // set Clock Prescaler Change Enable
    // set prescaler = 8, Inter RC 8Mhz / 8 = 1Mhz
    CLKPR = (0<<CLKPS1) | (1<<CLKPS0);
   USART_Init(103.08);
  
    while (1)
    {
        if (statetext){

         LCD_puts_f(statetext, 1);
         LCD_Colon(0);
         statetext = NULL;
}

         input = getkey();           // Read buttons
         switch (input) {
         case KEY_ENTER:
         statetext = PSTR("CENTRO");

            Usart_Tx('C');
            break;
         case KEY_NEXT:
            statetext = PSTR("RIGHT");
            Usart_Tx('R');
            break;
         case KEY_PREV:
            statetext = PSTR("LEFT");
            Usart_Tx('L');
            break;
         case KEY_PLUS:

            statetext = PSTR("UP");
            Usart_Tx('U');
            break;
         case KEY_MINUS:
            statetext = PSTR("DOWN");
            Usart_Tx('D');
         break;
         default:
            break;
    }  
    }
    return 0;
}


//**********************************
//LPC1769 CODE: MAIN.C


#include "LPC17xx.h"
#include "type.h"
#include "uart.h"
#include <string.h>

extern volatile uint32_t UART3Count;
extern volatile uint8_t UART3Buffer[BUFSIZE];

/*****************************************************************************
**   Main Function  main()
This program has been test on LPCXpresso 1700.
*****************************************************************************/
int main (void)
{
uint32_t i, j;

LPC_GPIO2->FIODIR = 0xFFFFFFFF;/* P2.xx defined as Outputs */
LPC_GPIO2->FIOCLR = 0xFFFFFFFF;


UARTInit(3, 9600);/* baud rate setting */


/* Loop forever */
while (1)
{
if ( UART3Count != 0 )
{
LPC_UART3->IER = IER_THRE | IER_RLS;/* Disable RBR */

if(*UART3Buffer==0x43){ // ASCII C
LPC_GPIO2->FIOSET  = 1 << 1;
for(j = 5000000; j > 0; j--);
LPC_GPIO2->FIOCLR = 0x000000FF;
for(j = 5000000; j > 0; j--);
}
if(*UART3Buffer==0x55){ // ASCII U

LPC_GPIO2->FIOSET = 1 << 5;
for(j = 5000000; j > 0; j--);
LPC_GPIO2->FIOCLR = 0x000000FF;
for(j = 5000000; j > 0; j--);
}
if(*UART3Buffer==0x44){ // ASCII D
LPC_GPIO2->FIOSET = 1 << 2;
for(j = 5000000; j > 0; j--);
LPC_GPIO2->FIOCLR = 0x000000FF;
for(j = 5000000; j > 0; j--);
}
if(*UART3Buffer==0x52){ // ASCII R

LPC_GPIO2->FIOSET = 1 << 3;
for(j = 5000000; j > 0; j--);
LPC_GPIO2->FIOCLR = 0x000000FF;
for(j = 5000000; j > 0; j--);
}
if(*UART3Buffer==0x4c){ // ASCII L

LPC_GPIO2->FIOSET = 1 << 4;
for(j = 5000000; j > 0; j--);
LPC_GPIO2->FIOCLR = 0x000000FF;
for(j = 5000000; j > 0; j--);
}

UART3Count = 0;
LPC_UART3->IER = IER_THRE | IER_RLS | IER_RBR;/* Re-enable RBR */
}
}
}

/*****************************************************************************
**                            End Of File
*****************************************************************************/

Outcomes