How can I use MOSI and MISO at 89S52 ? can I use serial port from computer, directly connected to these pins ? Any example codes for this function ?

Thanks a bunch enter image description here

enter image description here

enter image description here

Anyone has a code example, from the pictures above ?

  • 1
    \$\begingroup\$ Are you wanting to program the chip or communicate with it? You need to be clear and specific with your question, other wise you are liable to get the wrong answer ;-) \$\endgroup\$ – Oli Glaser Jan 10 '12 at 9:17

No, you can't connect these pins to the PC serial port.

The main reason is they are SPI pins, and you need to use the UART pins for this. The UART pins will be usually named RX and TX (though the datasheet will tell you)

Secondly, the voltages from the PC serial port are incompatible with your chip, so you you need something like the MAX232 suggested by AndrejaKo to translate the levels.

I suggest doing the following:

  • Read the Wiki page on UART (linked to above)
  • Read the datasheet - at the very least the UART section.
  • Google for examples of using UART for your chip.

For the last point I did a quick google for "89S52 UART example" and got quite a few relevant pages back.
Here is some basic example code for the UART from one of them:

#include <REGX52.h>
#include "delay.h" 
#include <stdio.h>        
unsigned char temperature; 
unsigned char humidity; 
void uartInit(void) 
 SCON  = 0x52;            
  TMOD  = TMOD|0x20;         
 TH1   = 0xfd;           
 TR1   = 1;        
void main(void) 
    printf("Temperature : %bu  Humidity : %bu \n", temperature++, humidity++);

EDIT - to use the SPI pins to connect to a PC, you need the PC to have an SPI capable interface (which don't come as standard on most machines) To add one you will need an SPI host adapter like this which can be plugged into the PCs USB port.

  • \$\begingroup\$ I have tried this one, but have no idea yet for MOSI and MISO, may be I need another device to convert from USB / serial to MOSI and MISO \$\endgroup\$ – Rick Ant Jan 10 '12 at 7:02
  • \$\begingroup\$ If you must use the SPI pins then you will need an adapter of some sort. See edit for one example. \$\endgroup\$ – Oli Glaser Jan 10 '12 at 7:12

First get the exact name of the component and read its datasheet. In it you will find what type of input the device expects. Usually computer serial port cannot be used directly with microcontrollers. Also the names of the ports suggest that this is synchronous serial port and you'll need the clock pin too (SCK I think it is called) and some way to drive it.

So to sum this up: It won't work directly with computer serial port but a circuit can be made to make the interface work somehow. Note that (if I remember correctly) for this type of device, the SCK/MOSI/MISO pins are used mainly for programming. If it has a serial port, you'll most likely need to use a chip such as MAX 232 to translate the voltages.

EDIT: In fact the datasheet was the first thing Google gave me after a search. Here's the link. Unfortunately, I don't have time to read it now (it's 3 AM here) and expand my answer, but you should definitely read it and (at least) the Wikipedia article on PC serial port.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.