CrazyEngineers Forum

******************************************
Welcome To CrazyEngineers (CE) – an online community of engineers from all over the world! With the younger CEan at 84 and the youngest at 16, CE boasts of professional engineers, students, professors, entrepreneurs, CEOs, geeks & nerds. We exchange innovative ideas, share knowledge, help each other and expand our worldwide network of engineers! You need not have a formal degree in engineering to be a part of CrazyEngineers! Need we say more?
Join CE! | CE Innovator Contest! | Forgot password? | Contact Us
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Electrical & Electronics Engineering
Reply

  #1 (permalink)
Old 24th June 2008, 10:55 AM
CE - Apprentice
 
I'm a Crazy Electrical Engineer
Join Date: 24th June 2008
Posts: 20
Question Reading in Data using a microcontroller

I'm not sure how digital serial input is read into the PIC. This is how I would guess it's done. You have a pin configured for input. You then have the first bit of data generate an interrupt. You then poll the input pin to see if the bit is a 1 or 0. You then store this value as the LSB at some location in memory. Then you wait for the next bit to come in. For example if the data is coming in at a rate of 10k bits/s then you would wait 0.1 ms and poll the input pin again and so forth until the MSB bit is read. Is this basically the general idea of how data is read in or does the PIC have a better way of doing it? Thanks for any help. I'm new at this stuff.
el3ktr1k is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)
Old 24th June 2008, 05:37 PM
CE - Enthusiast
 
just2rock's Avatar
 
I'm a Crazy Electronics & comm. Engineer
Join Date: 25th March 2007
Location: in ur arms!
Posts: 210
Send a message via Yahoo to just2rock
Default Re: Reading in Data using a microcontroller

Serial Input data is read in PIC as regard to the programing done into the microcontroller.Suppose you provide a data of Hex 12C8,then the controller will choose accordingly for its input.
just2rock is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)
Old 24th June 2008, 07:52 PM
CE - Apprentice
 
I'm a Crazy Electrical Engineer
Join Date: 24th June 2008
Posts: 20
Default Re: Reading in Data using a microcontroller

I still don't understand how the PIC is able to capture serial data and store it somewhere in memory. For example if I'm sending the binary byte, 01011001, from some to device to the input pin of a PIC, how would the PIC capture this value and store it in memory where I can call upon this value later?
el3ktr1k is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)
Old 25th June 2008, 10:26 AM
ash
Moderator
 
ash's Avatar
 
I'm a Crazy Communications Engineer
Join Date: 12th July 2007
Location: IIUM, Malaysia
Posts: 1,415
Default Re: Reading in Data using a microcontroller

Ah, heres the thing. I think you can't really send serial data directly into the input pins of the PIC easily (assuming you are talking about the Microchip variants). You'd need to use the Rx/Tx (recieve and transmission) pins to do all serial data communications.

In brief, microcontrollers are pretty much miniturized microprocessors, thus some of the architecture is similar. You have registers, interrupts, flags, and memory locations, etc. Whatever data is sent to the microcontroller, they will be stored in memory locations that have their own addresses. Each address location can store 8 bit of data (if you talking about an 8 bit microC). Thus, when you send the binary byte of 01011001, the microC will store it at a particular address in which the address register is pointing at. Whenever it wants to recall the byte, it'll just find the address, just like microprocessors.

So how do you recall the data? This depends on how you program the PIC. Using assembly language, you'd need to directly enter the address in which the data is stored into the address register, copy the data into a general purpose register, etc. However, if you use C programming, you only need to initialize a variable with a name of your choice, store the data, and then simply recall the variable (whether you want to print the data, add something, etc).

A note about polling it. PIC's (and perhaps other microcontrollers) have very limited memory to store instructions. Using the polling method to store serial data will bloat the code it for sure. Which ever way you program it, the final assembly code will contain lots of loops, delays, instructions to add bits, conditions to check the start and end bits, etc.

Use the dedicated Rx/Tx pins for those stuff Just set the required baud rate, inform the PIC that you are going to use serial, and you are good to go.
__________________
Keep it simple. Keep it real.
| New to CE? Click here! | Join our CE Bot project! | Problems? Questions? PM or mail me at ash{at]crazyengineers{dot]com |
ash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)
Old 25th June 2008, 01:17 PM
CE - Apprentice
 
I'm a Crazy Electrical Engineer
Join Date: 24th June 2008
Posts: 20
Default Re: Reading in Data using a microcontroller

Thank you Ash. I plan on using the PIC16F877 by Microchip. I looked at the data sheet and found the information about the Tx and Rx pins. I just wanted to make sure that I'm the right track with what I'm doing. I plan on using the standard 9600 baud rate with a 4 MHz crystal so it looks like the first thing I would do is give the SPRG register a value of 25 and set TXSTA<2>. It looks like I also need to clear bits 6 and 4 and set bit 5 of the TXSTA register to enable 8 bit asynchronous communication. It looks like I can then begin transmitting by moving data onto the TXREG register. For receiving data it looks like I set bits 7 and 4 and clear bit 6 of the RCSTA register to enable 8 asynchronous communication. It looks like the data would come in on the RCREG register and then i can move this to some location in file memory if I choose. I'm guessing most of this is a background process once the registers are set and I would just have to periodically check the RCREG register for incoming data. I'm not exactly sure how to tell the transmitter when the receiver's buffer is full or visa versa. I guess I poll the OERR bit and tell send a control byte to the transmitter to tell it to stop transmitting. Thank you for your help and any more insight would be appreciated.
el3ktr1k is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)
Old 8th July 2008, 10:42 AM
CE - Apprentice
 
I'm a Crazy Electrical Engineer
Join Date: 24th June 2008
Posts: 20
Default Re: Reading in Data using a microcontroller

There must still be something I'm doing wrong since I still can't figure out to get the microcontroller to communicate with my PC. Is there maybe some other register that I forgot about? I'm not sure. I'm using the RS232 port on my computer and converting that signal into the correct logic for the microcontroller by using a Max232 chip but it still doesn't seem to work.
I tried writing a simple program as a test that would take the data it receives and then just transmit it back but my program doesn't work. Thanks for any help.
el3ktr1k is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)
Old 8th July 2008, 01:22 PM
ash
Moderator
 
ash's Avatar
 
I'm a Crazy Communications Engineer
Join Date: 12th July 2007
Location: IIUM, Malaysia
Posts: 1,415
Default Re: Reading in Data using a microcontroller

How are you communicating to the microcontroller in the computer? Hyperterminal? Have you loaded the code into the microcontroller?
__________________
Keep it simple. Keep it real.
| New to CE? Click here! | Join our CE Bot project! | Problems? Questions? PM or mail me at ash{at]crazyengineers{dot]com |
ash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)
Old 8th July 2008, 07:27 PM
CE - Apprentice
 
I'm a Crazy Electrical Engineer
Join Date: 24th June 2008
Posts: 20
Default Re: Reading in Data using a microcontroller

I am using Matlab to send to the data the serial port and I have loaded the loaded the code to the microcontroller.
el3ktr1k is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)
Old 9th July 2008, 04:15 AM
CE - Apprentice
 
I'm a Crazy Electrical Engineer
Join Date: 24th June 2008
Posts: 20
Default Re: Reading in Data using a microcontroller

I think I may have the the wrong configuration for the type of oscillator that I'm using. This what I have in the beginning of my program:

list P=PIC16F877, F=INHX8M, C=160, N=80, ST=OFF, MM=OFF, R=DEC
include "P16F877.INC"
__config ( _CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF & _BODEN_OFF )
errorlevel -302 ;Ignore "error" when storing to Bank1

Like I mentioned before I'm trying to use a 4 MHz external crystal oscillator that has 4 pins. I would think that _XT_OSC would be the correct configuration for the type of oscillator that I'm trying to use but I guess I could be wrong.
el3ktr1k is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)
Old 10th July 2008, 03:25 AM
CE - Apprentice
 
I'm a Crazy Electrical Engineer
Join Date: 24th June 2008
Posts: 20
Default Re: Reading in Data using a microcontroller

I think I figured out what I was doing wrong. I noticed on the programmer board there was a jumper wire that was using the RC oscillator instead of the crystal oscillator. I still don't know how to make the PIC work on a bread board though. I basically wire up the 2 VDD pins to +5V and the two VSS pins to ground. I hook up pin 13 to the clock and I give pin 1 +5V.
el3ktr1k is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 06:47 AM.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.Ad Management by RedTyger