This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sending string on serial port

Hi everyone,

is there anyone who could help me with following?

In x51 processor You have SBUF buffer which is used to send or receive a character via serial port.
Is there any way to send a string? Not only a single character, but whole string?
I thought there could be any library which deals with it.
Or do I have to write it myself? I'm using Keil of course.

Would You be so kind and help?

Parents
  • I've got a problem.

    static void Nastav_seriovy_kanal (void)
    {
    	SCON = 0x50;
    	TMOD = TMOD | 0x20;
    	TH1 = 0xF4;
    	TL1 = 0xF4;
    	ES = 1;
    	TR1 = 1;
    }
    
    static void Preruseni_seriovy_kanal (void) interrupt 4
    {
    	if (RI == 1)
    	{
    	    RI = 0;
    	    if(SBUF == 'A') putchar('Q');
    	}
    	if (TI == 1) TI = 0;
    }

    I'm also including stdio.h, and string.h.

    I wonder why it doesn't work.

Reply
  • I've got a problem.

    static void Nastav_seriovy_kanal (void)
    {
    	SCON = 0x50;
    	TMOD = TMOD | 0x20;
    	TH1 = 0xF4;
    	TL1 = 0xF4;
    	ES = 1;
    	TR1 = 1;
    }
    
    static void Preruseni_seriovy_kanal (void) interrupt 4
    {
    	if (RI == 1)
    	{
    	    RI = 0;
    	    if(SBUF == 'A') putchar('Q');
    	}
    	if (TI == 1) TI = 0;
    }

    I'm also including stdio.h, and string.h.

    I wonder why it doesn't work.

Children
  • ATMEGA32:

    //-------------------------------------------------------------------------------
    // Zinicializuje UART
    void Serial_Init()
    {
        // Set baud rate
        UBRRH = 0;
        UBRRL = 71;								// 9600baud @ 11.0592MHz
    
    	UCSRB=(1<<RXCIE)|(1<<RXEN)|(1<<TXEN);	// povolim RX, TX a preruseni od RX
    
    	UCSRC=(1<<URSEL)|(3<<UCSZ0);			// D=8, P=0, S=1
    }
    
    
    //---------------------------------------------------------------------------------
    // signal handler for receive complete interrupt
    SIGNAL(SIG_UART_RECV){
    char aku;
    int temp, h, l;
    
    
    	aku=UDR;
    ...
    }
    
    
    //---------------------------------------------------------------------------------------------
    void PutStr(char *p){	// Posle string
    	while (*p) {
    		PutChar (*p++);
    	}
    }
    

  • "ATMEGA32"

    Why are you posting AVR code for a non-Keil compiler??

    That's almost entirely irrelevant, since issues related to Port IO and interrupts a almost entirely target- and compiler-specific!

    Keil does not have a SIGNAL macro or keyword - and it's deprecated in AVR-GCC anyhow!

  • I think the SIGNAL is a debugger thing,
    for generating code that runs to simulate
    event for the controller.

  • "I think the SIGNAL is a debugger thing for generating code that runs to simulate event for the controller."

    Yes, uVision has "Signal Functions" - but that was not uVision syntax.

    It was definitely AVR source code - he said so himself: "ATMEGA32" (that's an AVR)

  • Hi, the point was the while loop sending string to USART. Sorry... Mirek