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

settng up rs232 variable

Hi, can anyone tell me how i would set up a variable that expects a certain amount of data to be received through rs232.

i.e. to receive 18 bytes of data only once the the rx pin has been set to input.

thanks guys

Parents
  • "tell me how i would set up a variable that expects a certain amount of data to be received through rs232."

    Variables don't "expect" anything. You need to write software that can be in a state of "expecting".

    Also, variables neither know nor care where their data comes from - they just hold it.

    In 'C', I suggest that you think about an array or, perhaps, that special case of an array - the string.

    Receiving asynchronous serial data at the RI pin will involve using the UART.

    Connecting true RS232 voltage levels to the RI pin will probably damage it - be sure to use an RS232 transceiver (eg, MAX232).

Reply
  • "tell me how i would set up a variable that expects a certain amount of data to be received through rs232."

    Variables don't "expect" anything. You need to write software that can be in a state of "expecting".

    Also, variables neither know nor care where their data comes from - they just hold it.

    In 'C', I suggest that you think about an array or, perhaps, that special case of an array - the string.

    Receiving asynchronous serial data at the RI pin will involve using the UART.

    Connecting true RS232 voltage levels to the RI pin will probably damage it - be sure to use an RS232 transceiver (eg, MAX232).

Children
  • Connecting true RS232 voltage levels to the RI pin will probably damage it - be sure to use an RS232 transceiver (eg, MAX232).

    in if you write a zero to p0.1 you will burn either the RS232 transceiver or the '51 or both. I assumed he did, if not the above should be "you will burn the '51 whatever you set P0.1 to"

    Erik

  • No its ok, i am using a max232 transceiver, its all connected and i can output and input characters through rs232. The idea of the project is for a wireless weather station. i am in charge of programming the wireless side and i will receive a string of 144 bits (18 bytes) each byte of which, will represent a character. I am struggling to write c code that can handle the bytes and then send them wirelessly using the nrf24e1. Is it possible to just use getchar() to receive an individual character as i will be connected to the sensor side of the weather station through Rx/Tx pins configures as rs232 8 bits and 1 parity? or is there a better way of doing this?

    thanks for your help.

  • once you are doing 'special stuff' I suggest you do not use the 'standard' stuff such as getchar.

    a routine to receive UART data is about 10 lines in the ISR and about 5 lines in the main.

    Why do you not want to receive whatever comes in on the Rx?

    forget about bits, the UART handles bytes

    Erik

  • because what comes through the UART is the data from the sesor board of the weather station, i.e. the temperature, pressure etc which is placed on a rooftop. this comes to my transmitter through UART which i then have to transmit to the receiver which outputs this data to an ethernet board that is connected to the database. I agree getchar is not great...but im unfarmiliar with embedded c and need some basic direction.

  • There is example code in the Support section of this website (see Downloads), and it's also in the Examples folder in your PC installation.

    Reading list:
    http://www.keil.com/books/8051books.asp
    www.8052.com/books.phtml

    The ACCU (Association of C & C++ Users) also has a whole load of book reviews - including a section on embedded:

    brian.accu.org/.../

  • "i will receive a string of 144 bits"

    If you're going to use the UART, it has to be sent as 18 bytes - each one complete with start & stop bits.

    Is that the case?

  • Yes as 18 bytes, this is the case, I am now at the point where i have set-up a counter which just incriments the ascii table to send unspecified characters wirelessly.... but its the initial receiving of the bytes at the transmission side i am unsure of with regards as to how do i set-up a function to receive the 18 bytes...as i am currently using getchar to receive each byte. hope im clear.

  • hope im clear

    you are not

    WHY do you wnat to receive just 18 bytes, not everything the unit send to you?

    Erik

  • Well technically i do, but the unit will only send me 18 bytes every minute. which will contain all the weather data, i do not need to know what the data is, just that there is 18 bytes of raw data.

  • so, are you saying that all your unit has to do is to receive characters/bytes and resend them?

    what is the baudrate in and out?

    Erik

  • Yes that is basically all i hacve to do, although i will need to write the bytes to eeprom for storage as a backup if the sending fails which if it does then they can be resent. the baud rate is 9600.

  • you have all the processing time you need to run this simple task at 9600, so
    1) write the code
    2) debug it
    3) smile

    I would totally forget all about using library functions, let the sensor write to a circular buffer, upon receiving characters wait for previous byte tranamit complete (TI should be almost immediate) and transmit the char. Let main take care of storing from the circular buffer to the EEPROM.

    NOTE: if you bit-bang the EEPROM you WILL "have a lot of fun" doing this, select a derivative that can drive the EEPRROM (IIC, SPI or whatever) through hardware.

    Erik

  • Hi well this is the code i have atm for the transmitter:

    void TRANSMITTER(void)
    {
    
    
        unsigned char Mode;
            unsigned char b;
            unsigned char Packet;
            unsigned int address;
    
            if (Mode == 'd')
            {
                Packet = GetChar();
                    Configuration();
                    DELAY_100us(200);
                            for(b=0;b<txconf.n;b++)
                                            {
                                            SPI_ReadWrite(txconf.buf[b]);
                                            }
                                                    Standby();
                                                    DELAY_100us(200);
                                    for (address=0x00;address<0xff;address++)
                                {
                            EEWrite(address,Packet);
                            }
                                                    for (Packet=0;Packet<18;Packet++)
                                                    {
                                                    TRANSMIT_Packet(Packet);
                                                    }
    
            }
    
    }
    
    


    if (Mode == 'd') is just for the pulse pin i have set up to ensure the data to be received is data and not a command
    as can be seen i have set up an unsigned char Packet and i am using Packet = GetChar(); to retreive the byte.....if i remove the GetChar() how can i assign the byte received to Packet to ensure that byte is sent, further down the code?

    Cheers Rhys

  • can someone please analyse this code? thanks

  • can someone please analyse this code

    HOW?

    what does packet() do ?
    what does configuration() do: ?
    why do you indent 'a mile' use spaces, not table?

    Erik

    PS: you have two options a) wait till it may be convenient for a responder if you want it for free OR b) pay for it.

    Do you really think there are people sitting around just waiting to solce your problem for free?