I'm trying to make digital clock using DS3234 with AT89C51AC3 ...i'm using keil uVison v.2.4oa.... i'm using one of the SPI example listed on website under AT89C51AC3 section .. when i try to run SPI of uC i dont see any SCLK on CRO.. no MOSI/MISO data ...i mean SPI is not working at all....when i saw its header file.... it was for XD2 controller...so SPI registers address were of RD2...i edited them acc. to address map in datasheet....but still it doesnt work..all other programs work fine(timer/ADC/EEPROM)..where is the problem ?
here is the example code...
#include "reg_c51.h" char serial_data; char data_example=0x55; char data_save; bit transmit_completed= 0;
void main(void) { SPCON |= 0x10; /* Master mode */ SPCON |= 0x82; /* Fclk Periph/128 */ SPCON |= 0x20; /* P1.1 is available as standard I/O pin */ 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) { P1_1=0; // LED Blink SPDAT=data_example; // send an example data while(!transmit_completed);// wait till end transmit_completed = 0; // clear flag SPDAT=0x00; //data is send to gen SCK signal while(!transmit_completed); // wait till end transmit_completed = 0; //clear flag data_save = serial_data; // save receive data P2=data_save; //LED blink } } void it_SPI(void) interrupt 9 //int add is 0x004B { switch ( SPSCR ) // read and clear status { 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; } }