receive/transmit over rs232 with arm lpc2148 on sparkfun logomatic

1

I am trying to program the logomatic by sparkfun, and yes I have used their forum with no responses, and having some issues. I am trying to send characters to the UART0 and I want the logomatic to respond with specific characters and not just an echo. For example, I send 'ID?' over the terminal (using RealTerm), and the logomatic sends back '1'. All it will so now is echo.

I am using c with programmers notepad with the WinARM toolchain. The following snippet is from the main.c file. I only included this, because I am fairly certain that this is where my problem lies

void Initialize(void)
{
    rprintf_devopen(putc_serial0);   

    PINSEL0 = 0xCF351505;
    PINSEL1 = 0x15441801;
    IODIR0 |= 0x00000884;
    IOSET0 = 0x00000080;

    S0SPCR = 0x08;  // SPI clk to be pclk/8
    S0SPCR = 0x30;  // master, msb, first clk edge, active high, no ints
}

Notice the rprintf_devopen function, below is from the rprintf.c file, and due to my mediocre skills, I do not understand this bit of code. If I comment out the rprintf_devopen in main, the chip never initializes correctly.

static int (*putcharfunc)(int c);

void rprintf_devopen( int(*put)(int) )
{
    putcharfunc = put;
}

static void myputchar(unsigned char c)
{
    if(c == '\n') putcharfunc('\r');
    putcharfunc(c);
}

Now, below is from the serial.c file. So my thought was that I should be able to just call one of these putchar functions in main.c and that it would work, but it still just echoes.

int putchar_serial0 (int ch)
{
    if (ch == '\n')
    {
        while (!(U0LSR & 0x20));
        U0THR = CR;                  // output CR 
    }
    while (!(U0LSR & 0x20));
    return (U0THR = ch);
}

// Write character to Serial Port 0 without \n -> \r\n  
int putc_serial0 (int ch)
{
    while (!(U0LSR & 0x20));
    return (U0THR = ch);
}

// Write character to Serial Port 1 without \n -> \r\n  
int putc_serial1 (int ch)
{
    while (!(U1LSR & 0x20));
    return (U1THR = ch);
}

void putstring_serial0 (const char *string)
{
    char ch;

    while ((ch = *string))
    {
        putchar_serial0(ch);
        string++;
    }
}

I have tried calling the different putchar functions in main, also with the rprintf_devopen. Still just echoes. I have altered the putchar functions and still just echoes. I have tried just writing to the U0THR register in main.c and no luck. Keep in mind that I am still a student and my major is electrical engineering, so the only programming classes that I have taken are intro to c, and an intro to vhdl. I am more of a math and physics guy. I was working on this for an internship I was doing. The internship ended, but it just bugs me that I cannot figure this out. Honestly, working on this program taught me more that the c class that I took. Anyways, I appreciate any help that can be offered, and let me know if you want to see the entire code.

Below is an update to the question. This function is in main.c

static void UART0ISR(void)
{
char temp;
trig = 13; //This is where you set the trigger character in decimal, in this case a carriage return.
temp = U0RBR; //U0RBR is the receive buffer on the chip, refer to datasheet.

if(temp == query1[counter1]) //This segment looks for the characters "ID?" from the U0RBR
{                             //query1 is defined at the top of the program
    counter1++;
    if(counter1 >= 3)
    {
        flag1 = 1;           //This keeps track of whether or not query1 was found
        counter1 = 0;

        stat(1,ON);
        delay_ms(50);
        stat(1,OFF);

        RX_in = 0;
        temp = 0;
        //rprintf("\n\rtransmission works\n");
        putc_serial1(49);    
    }                        
}

if(temp == query2[counter2] && flag1 == 1) //This segment looks for "protov?" from the U0RBR, but only after query1 has been found
{
    counter2++;
    if(counter2 >= 7)
    {
        flag2 = 1;             //This keeps track of whether or not query2 was found
        counter2 = 0;

        stat(1,ON);
        delay_ms(50);
        stat(1,OFF);

        RX_in = 0;
        temp = 0;
        putc_serial1(49);    
    }                        
}

if(temp == stop[counter3]) //This if segment looks for certain characters in the receive buffer to stop logging
{
    counter3++;
    if(counter3 >= 2)
    {
        flagstop = 1;       //This flagstop keeps track of whether or not stop was found. When the stop characters are found,
        flag1 = 0;          //the query1 and query2 flags will be reset. So, in order to log again these queries must be sent again
        flag2 = 0;          //this may seem obvious, but deserves mention.
        counter3 = 0;

        stat(1,ON);
        delay_ms(500);
        stat(1,OFF);

        RX_in = 0;
        temp = 0;
    }
    flagstop = 0;           //Reset the stop flag in order to wait once again for the query 1&2
}

if(RX_in == 0)
{
    memset (RX_array1, 0, 512); // This clears the RX_array to make way for new data
    memset (RX_array2, 0, 512);
}   

if(RX_in < 512 && flag1 == 1 && flag2 == 1) //We cannot log data until we see both flags 1 & 2 and after we see these flags,
{                                             //we must then see the trigger character "carriage return"
    RX_array1[RX_in] = temp;
    RX_in++;

    if(temp == trig)
    {
        RX_array1[RX_in] = 10; // delimiters
        log_array1 = 1;
        RX_in = 0;
    }
}   
else if(RX_in >= 512 && flag1 == 1 && flag2 == 1) //This else if is here in case the RX_in is greater than 512 because the RX_arrays are defined to
{                                                   //be of size 512. If this happens we don't want to lose data, so we must put the overflow into another register. 
    RX_array2[RX_in - 512] = temp;
    RX_in++;
    RX_array1[512] = 10; // delimiters
    RX_array1[512 + 1] = 13;
    log_array1 = 1;

    if(RX_in == 1024 || temp == trig)
    {
        RX_array2[RX_in - 512] = 10; // delimiters
        log_array2 = 1;
        RX_in = 0;
    }
}

temp = U0IIR; // have to read this to clear the interrupt

VICVectAddr = 0;
}
c
lpc
asked on Stack Overflow Aug 5, 2015 by Frank • edited Aug 5, 2015 by Weather Vane

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0