Jump to content
Sign in to follow this  
BruteForce

Transmitting Serial data (ASCII) received from the computer to external LED circuit

Recommended Posts

Hi there!

I am not very much experienced in MSP430 platform. I am kind of stuck in a problem. Let me describe my project goal first. What I want to do is:

1) I will input a letter (suppose "K") via serial monitor to my MSP430G2553,

2) Upon receiving the letter, the launchpad will vary the voltage level a GPIO PIN (let's assume P1.4) based on the input, which is connected to an LED,

3) As the LED blinks based on the input bit pattern (K, ASCII value = 75, Binary equivalent = 01001011), one light dependent resistor will read this variation, which is connected to another Launchpad, and stores it a buffer

4) The launchpad will read this buffer value, and print it to serial monitor

So, this is essentially a chat module between two launchpad, using serial monitor and some electronic stuff.

My Problem:

(I am using Energia for coding) I can read the character from Energia Serial Monitor, however, I don't know

1. How to transmit the received BIT pattern through a GPIO pin, towards a external LED. I am using the Hardware UART for communication with computer- Is there any other way, I can send data serially over regular GPIO PINs?


Please let me know, if my question requires further clarification. I am working on it... if I can solve it, or have any update, I am gonna post it here. I'd really appreciate your help. Thank you in advance!

Share this post


Link to post
Share on other sites

Hi BruteForce, BTW don't you think a optocoupler is more close to what you need? It's a integrated solution to the LED+LDR combo. Just trowing it out there in case you don't know it.

So you want to receive data from Serial, send it over, bit by bit, to another launchpad which will then send it by serial into the computer correct?
Seems pretty simple, what you require is to extract from each char received, each bit.

Example:

Imagine you have them in a array like StringReceived[].
So you just have to do to send each char:

for(int i = 0; i < 8; i++)

    digitalWrite(pin, ( StringReceived[n] & (1 << i) );

 

Being "n" the number of the char you want to send. See if you understand what I am doing above. I isolate each bit from the character, one at a time. The operation StringReceived[n] & (1 << i)  will either give 0 or (1<<i), basically false or true (set the output to 0 or 1  0v or 3.3V). I am not sure if the function digitalWrite() accepts the (1<<i), you could simply add a if/else pair if that is the case.
Now how do you receive the data by serial, I am not familiar with data in Energia, I'm sorry I can't help you with that. There are good examples included in Energia for receiving data over serial, check them out.

Share this post


Link to post
Share on other sites
#define GPIO 11 //random digital pin
  
void setup() {                
  pinMode(GPIO, OUTPUT);     
}

void loop() {
  //get char from serial monitor
  //convert char into an array with 8 value (lets say, tranData[] - add to setup)
  for (int i = 0; i < 8; i++) {
    if (tranData[i] == 1) { digitalWrite(GPIO, HIGH); }
    else { digitalWrite(GPIO, LOW); } 
  }
}

In this case, your array should look something like an 8-bit binary value. 

 

If the data bit in the i-th position of the array is a 1, GPIO pin will go high (3.3v), else it will go low (0v).

 

Use the voltages from the IO pin to transmit a high or low signal to your other MSP.  Now you need to probably add a delay in between loop iterations so keep that in mind - remember your transmitting speed.  You may also want to send a high signal to indicate data is about to be sent to your receiving MSP.

 

On the transmitting side, receive the transmitted signal and feed it into an LED and into a digital input pin. When you get a high signal (the indicator signal), go into a loop that loops at your transmitting speed and read the next 8 bits that are transmitted, and save them into a variable.

 

For example, you transmit once every 10ms -> send a high and delay for 10ms, then send your 8-bit value 1 bit at a time every 10ms.  When you receive the initial high signal, start reading the state of the receiving input pin once every 10ms (starting 10ms after the indicator signal), do this in a loop 8 times to save all 8 bits.  Now you have all 8 bits saved, and you can translate that into the corresponding ascii value and print it to the serial monitor.

 

Fair warning: I am by no means a pro at this, your project just seemed a bit interesting to me, and this is how i would approach it (with what little experience I have). - there could very well be a better way.

Share this post


Link to post
Share on other sites

Thanks  everyone. 

 

Just to test whether the logic is working fine, I wrote this sample piece of code:

 

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(4800);
  
}
void loop()
{
  // put your main code here, to run repeatedly:
  char c = 'A';


  for (int i = 7; i >= 0; --i)
   {
       Serial.println( (c & (1 << i)) ? '1' : '0' );   
   }
   Serial.print("\n");
   delay(1000);
}

I noticed one interesting thing- I can only see "readable" output when the baud rate is set to 9600. With baud rate less than that, i.e., 4800 or 1200, I see some gibberish, non human readable characters. Can anyone help me why is this happening? 

I am asking because, due to the nature of my project, I may need to slow down a bit while transmitting or receiving data. Thank you in advance,

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...