drbizzarow
Advanced Member level 1
- Joined
- May 24, 2006
- Messages
- 414
- Helped
- 25
- Reputation
- 50
- Reaction score
- 15
- Trophy points
- 1,298
- Activity points
- 3,662
hi,
reference to this topic. https://www.edaboard.com/threads/173914/
I am facing same problem in Proteus simulation. I am trying to use 89c51ed2 spi port.
I am using Atmel sample code for spi but nothing is happening on spi port.
In my code i have also used its UART port and its working fine.
Can any body tell me what is the problem ????
here is my code:
#include "reg_c51.h"
//#include <AT89C51RB2.H>
//#include <intrins.h>
#include <stdio.h>
#include <string.h>
//////////////////////////////////
// PIN ASSINGMENTS //
//////////////////////////////////
//-------General Peraphirals
sbit SYS_LED = P1^0;
sbit SES_LED = P1^1;
//-----MACROS
#define HIGH 1
#define LOW 0
#define SYS_LED_ON SYS_LED = LOW;
#define SYS_LED_OFF SYS_LED = HIGH;
#define BUZZER_ON BUZZER = HIGH;
#define BUZZER_OFF BUZZER = LOW;
#define SERIAL_PACKET_SIZE 20
#define BUFERS_SIZE SERIAL_PACKET_SIZE - 2
#define TIMER0_RELOAD_VALUE -0x2e //for 50ms time interval
void serialTx(unsigned char chr);
//////////////////////////////////////////////
// GLOBAL VERIABLES DECLERATIONS //
//////////////////////////////////////////////
char serial_data;
char data_example=0x55;
char data_save;
bit transmit_completed= 0;
char x;
/*----------------------------------Interrupts--------------------------------------*/
/**
* FUNCTION_PURPOSE:interrupt
* FUNCTION_INPUTS: void
* FUNCTION_OUTPUTS: transmit_complete is software transfert flag
*/
void it_SPI(void) interrupt 9 /* interrupt address is 0x004B */
{
serialTx('i');
switch ( SPSTA ) /* read and clear spi status register */
{
case 0x80:
serial_data=SPDAT; /* read receive data */
transmit_completed=1;/* set software flag */
break;
case 0x10:
/* put here for mode fault tasking */
break;
case 0x40:
/* put here for overrun tasking */
break;
}
}
void serial_interrupt(void) interrupt 4 using 2 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~SERIAL ISR*/
{
if (RI)
{
if(SBUF == 'O')
SES_LED = LOW;
else
SES_LED = HIGH;
RI = 0;
/*SPackRcv_FLAG = LOW;
SerialBuff[SerialBuffIndex] = SBUF;
RI = 0;
SerialBuffIndex++;
if(SerialBuffIndex >= SERIAL_PACKET_SIZE) SerialBuffIndex = 0; // incase of serial buffer overflow*/
}
}
/*-------------------------------------UDF--------------------------------------------*/
void delay(unsigned int times)
{
unsigned char i;
while(times-- > 0)
{
i = 255;
while(i-- > 0)
{
i = i;
}
}
}
void serialTx(unsigned char chr)
{
SBUF= chr;
while (!TI);
TI= 0;
}
/**
* FUNCTION_PURPOSE: This file set up spi in master mode with
* Fclk Periph/128 as baud rate and with slave select pin.
* FUNCTION_INPUTS: P1.5(MISO) serial input
* FUNCTION_OUTPUTS: P1.7(MOSI) serial output
*/
void main(void)
{ /*--------Bismillah-------*/
/* setup Serial interrupt */
TMOD = TMOD | 0x20; //TIMER1 IN MOD2 (AUTO RELOAD)
TH1 = -3; //BAUD RATE = 9600bps @ 11.0592MHz
TR1 = 1; //RUN TIMER1 FOR SERIAL CLOCK
SCON = 0x52; //8BIT, 1STOPBIT, NO PARITY
RI = 0;
TI = 0;
ES = 1; //ENABLE SERIAL INT
/* setup timer 0 interrupt */
// TR0 = 0;
// TH0 = 0X4B;
// TL0 = 0xFD; // set timer period
// TMOD = TMOD | 0x01; // select mode 1
// TR0 = 1; // start timer 0
/* Ext0 interrupt Settings */
//IT1 = 1; //ext0 neg edge trigger
/*SPI Settings And Interrupt */
SPCON = 0x00;
SPCON = 0x10; /* Master mode */
P1_1=1; /* enable master */
SPCON |= 0x82; /* Fclk Periph/128 */
SPCON &= ~0x08; /* CPOL=0; transmit mode example */
SPCON |= 0x04; /* CPHA=1; transmit mode example */
IEN1 |= 0x04; /* enable spi interrupt */
SPCON |= 0x40; /* run spi */
EA=1; /* enable interrupts */
while(1) /* endless */
{
serialTx('R');
transmit_completed = 0;
while(1)
{
switch ( SPSTA ) /* read and clear spi status register */
{
case 0x00:
serialTx('0');
break;
case 0x80:
serialTx('8');
break;
case 0x10:
serialTx('1');
break;
case 0x40:
serialTx('4');
break;
}
}
SPDAT=data_example; /* send an example data */
while(!transmit_completed);/* wait end of transmition */
serialTx('X');
transmit_completed = 0; /* clear software transfert flag */
SPDAT=0x00; /* data is send to generate SCK signal */
while(!transmit_completed);/* wait end of transmition */
transmit_completed = 0; /* clear software transfert flag */
data_save = serial_data; /* save receive data */
delay(100);
}
}
- - - Updated - - -
any body plssss..... if so one have similar experience ?
reference to this topic. https://www.edaboard.com/threads/173914/
I am facing same problem in Proteus simulation. I am trying to use 89c51ed2 spi port.
I am using Atmel sample code for spi but nothing is happening on spi port.
In my code i have also used its UART port and its working fine.
Can any body tell me what is the problem ????
here is my code:
#include "reg_c51.h"
//#include <AT89C51RB2.H>
//#include <intrins.h>
#include <stdio.h>
#include <string.h>
//////////////////////////////////
// PIN ASSINGMENTS //
//////////////////////////////////
//-------General Peraphirals
sbit SYS_LED = P1^0;
sbit SES_LED = P1^1;
//-----MACROS
#define HIGH 1
#define LOW 0
#define SYS_LED_ON SYS_LED = LOW;
#define SYS_LED_OFF SYS_LED = HIGH;
#define BUZZER_ON BUZZER = HIGH;
#define BUZZER_OFF BUZZER = LOW;
#define SERIAL_PACKET_SIZE 20
#define BUFERS_SIZE SERIAL_PACKET_SIZE - 2
#define TIMER0_RELOAD_VALUE -0x2e //for 50ms time interval
void serialTx(unsigned char chr);
//////////////////////////////////////////////
// GLOBAL VERIABLES DECLERATIONS //
//////////////////////////////////////////////
char serial_data;
char data_example=0x55;
char data_save;
bit transmit_completed= 0;
char x;
/*----------------------------------Interrupts--------------------------------------*/
/**
* FUNCTION_PURPOSE:interrupt
* FUNCTION_INPUTS: void
* FUNCTION_OUTPUTS: transmit_complete is software transfert flag
*/
void it_SPI(void) interrupt 9 /* interrupt address is 0x004B */
{
serialTx('i');
switch ( SPSTA ) /* read and clear spi status register */
{
case 0x80:
serial_data=SPDAT; /* read receive data */
transmit_completed=1;/* set software flag */
break;
case 0x10:
/* put here for mode fault tasking */
break;
case 0x40:
/* put here for overrun tasking */
break;
}
}
void serial_interrupt(void) interrupt 4 using 2 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~SERIAL ISR*/
{
if (RI)
{
if(SBUF == 'O')
SES_LED = LOW;
else
SES_LED = HIGH;
RI = 0;
/*SPackRcv_FLAG = LOW;
SerialBuff[SerialBuffIndex] = SBUF;
RI = 0;
SerialBuffIndex++;
if(SerialBuffIndex >= SERIAL_PACKET_SIZE) SerialBuffIndex = 0; // incase of serial buffer overflow*/
}
}
/*-------------------------------------UDF--------------------------------------------*/
void delay(unsigned int times)
{
unsigned char i;
while(times-- > 0)
{
i = 255;
while(i-- > 0)
{
i = i;
}
}
}
void serialTx(unsigned char chr)
{
SBUF= chr;
while (!TI);
TI= 0;
}
/**
* FUNCTION_PURPOSE: This file set up spi in master mode with
* Fclk Periph/128 as baud rate and with slave select pin.
* FUNCTION_INPUTS: P1.5(MISO) serial input
* FUNCTION_OUTPUTS: P1.7(MOSI) serial output
*/
void main(void)
{ /*--------Bismillah-------*/
/* setup Serial interrupt */
TMOD = TMOD | 0x20; //TIMER1 IN MOD2 (AUTO RELOAD)
TH1 = -3; //BAUD RATE = 9600bps @ 11.0592MHz
TR1 = 1; //RUN TIMER1 FOR SERIAL CLOCK
SCON = 0x52; //8BIT, 1STOPBIT, NO PARITY
RI = 0;
TI = 0;
ES = 1; //ENABLE SERIAL INT
/* setup timer 0 interrupt */
// TR0 = 0;
// TH0 = 0X4B;
// TL0 = 0xFD; // set timer period
// TMOD = TMOD | 0x01; // select mode 1
// TR0 = 1; // start timer 0
/* Ext0 interrupt Settings */
//IT1 = 1; //ext0 neg edge trigger
/*SPI Settings And Interrupt */
SPCON = 0x00;
SPCON = 0x10; /* Master mode */
P1_1=1; /* enable master */
SPCON |= 0x82; /* Fclk Periph/128 */
SPCON &= ~0x08; /* CPOL=0; transmit mode example */
SPCON |= 0x04; /* CPHA=1; transmit mode example */
IEN1 |= 0x04; /* enable spi interrupt */
SPCON |= 0x40; /* run spi */
EA=1; /* enable interrupts */
while(1) /* endless */
{
serialTx('R');
transmit_completed = 0;
while(1)
{
switch ( SPSTA ) /* read and clear spi status register */
{
case 0x00:
serialTx('0');
break;
case 0x80:
serialTx('8');
break;
case 0x10:
serialTx('1');
break;
case 0x40:
serialTx('4');
break;
}
}
SPDAT=data_example; /* send an example data */
while(!transmit_completed);/* wait end of transmition */
serialTx('X');
transmit_completed = 0; /* clear software transfert flag */
SPDAT=0x00; /* data is send to generate SCK signal */
while(!transmit_completed);/* wait end of transmition */
transmit_completed = 0; /* clear software transfert flag */
data_save = serial_data; /* save receive data */
delay(100);
}
}
- - - Updated - - -
any body plssss..... if so one have similar experience ?