#ifndef __SPI__H__
#define __SPI__H__
extern unsigned char time_y = 8;
void SPI_Master_GPIO_Init(void)
{
PC_DDR|=(1<<6 mosi="" nbsp="" span="">6>
PC_CR1|=(1<<6 span="">6>
PC_CR2&=~(1<<6 span="">6>
PC_DDR|=(1<<5 nbsp="" span="">5>
PC_CR1|=(1<<5 span="">5>
PC_CR2&=~(1<<5 span="">5>
PA_DDR|=(1<<3 nbsp="" out="" span="">3>
PA_CR1|=(1<<3 span="">3>
PA_CR2&=~(1<<3 span="">3>
PC_DDR&=~(1<<7 in="" miso="" nbsp="" span="">7>
PC_CR1|=(1<<7 span="">7>
PC_CR2&=~(1<<7 span="">7>
}
void CSN_low (void)
{
PA_ODR &= ~(1<<3 span="">3>
}
void CSN_high (void)
{
PA_ODR |= (1<<3 span="">3>
}
void SPI_Slave_GPIO_Init(void)
{
PC_DDR&=~(1<<6 span="">6>
PC_CR1|=(1<<6 span="">6>
PC_CR2&=~(1<<6 span="">6>
PC_DDR&=~(1<<5 span="">5>
PC_CR1|=(1<<5 span="">5>
PC_CR2&=~(1<<5 span="">5>
PA_DDR&=~(1<<3 span="">3>
PA_CR1|=(1<<3 span="">3>
PA_CR2&=~(1<<3 span="">3>
PC_DDR|=(1<<7 span="">7>
PC_CR1|=(1<<7 span="">7>
PC_CR2&=~(1<<7 span="">7>
}
void send_char (unsigned int temp)
{
unsigned char j = 0, i = 0;
for(i=0;i<8 i="" span="">8>
{
j = 7-i;
PC_ODR &= ~(1<<5 span="">5>
if((temp>>j) & 0x01)
PC_ODR |= (1<<6 span="">6>
else
PC_ODR &= ~(1<<6 span="">6>
time_y = 8;
while(time_y--);
PC_ODR |= (1<<5 span="">5>
time_y = 8;
while(time_y--);
PC_ODR &= ~(1<<5 span="">5>
}
}
unsigned char get_char (void)
{
unsigned char j = 0, i = 0;
for(i=0;i<8 i="" span="">8>
{
unsigned char k = 7-i;
PC_ODR &= ~(1<<5 span="">5>
time_y = 8;
while(time_y--);
PC_ODR |= (1<<5 span="">5>
if(PC_IDR & (1<<7 span="">7>
{
j |= (1<
}
else
time_y = 8;
while(time_y--);
PC_ODR &= ~(1<<5 span="">5>
}
return j;
}
void write_n_byte (unsigned char add,unsigned char no_of_byte,unsigned char *string_data)
{
unsigned char i = 0;
add |=0x20;
send_char(add);
for (i = 0; i < no_of_byte ; i++)
{
send_char(*string_data+i);
}
}
#endif
#define __SPI__H__
extern unsigned char time_y = 8;
void SPI_Master_GPIO_Init(void)
{
PC_DDR|=(1<<6 mosi="" nbsp="" span="">6>
PC_CR1|=(1<<6 span="">6>
PC_CR2&=~(1<<6 span="">6>
PC_DDR|=(1<<5 nbsp="" span="">5>
PC_CR1|=(1<<5 span="">5>
PC_CR2&=~(1<<5 span="">5>
PA_DDR|=(1<<3 nbsp="" out="" span="">3>
PA_CR1|=(1<<3 span="">3>
PA_CR2&=~(1<<3 span="">3>
PC_DDR&=~(1<<7 in="" miso="" nbsp="" span="">7>
PC_CR1|=(1<<7 span="">7>
PC_CR2&=~(1<<7 span="">7>
}
void CSN_low (void)
{
PA_ODR &= ~(1<<3 span="">3>
}
void CSN_high (void)
{
PA_ODR |= (1<<3 span="">3>
}
void SPI_Slave_GPIO_Init(void)
{
PC_DDR&=~(1<<6 span="">6>
PC_CR1|=(1<<6 span="">6>
PC_CR2&=~(1<<6 span="">6>
PC_DDR&=~(1<<5 span="">5>
PC_CR1|=(1<<5 span="">5>
PC_CR2&=~(1<<5 span="">5>
PA_DDR&=~(1<<3 span="">3>
PA_CR1|=(1<<3 span="">3>
PA_CR2&=~(1<<3 span="">3>
PC_DDR|=(1<<7 span="">7>
PC_CR1|=(1<<7 span="">7>
PC_CR2&=~(1<<7 span="">7>
}
void send_char (unsigned int temp)
{
unsigned char j = 0, i = 0;
for(i=0;i<8 i="" span="">8>
{
j = 7-i;
PC_ODR &= ~(1<<5 span="">5>
if((temp>>j) & 0x01)
PC_ODR |= (1<<6 span="">6>
else
PC_ODR &= ~(1<<6 span="">6>
time_y = 8;
while(time_y--);
PC_ODR |= (1<<5 span="">5>
time_y = 8;
while(time_y--);
PC_ODR &= ~(1<<5 span="">5>
}
}
unsigned char get_char (void)
{
unsigned char j = 0, i = 0;
for(i=0;i<8 i="" span="">8>
{
unsigned char k = 7-i;
PC_ODR &= ~(1<<5 span="">5>
time_y = 8;
while(time_y--);
PC_ODR |= (1<<5 span="">5>
if(PC_IDR & (1<<7 span="">7>
{
j |= (1<
}
else
time_y = 8;
while(time_y--);
PC_ODR &= ~(1<<5 span="">5>
}
return j;
}
void write_n_byte (unsigned char add,unsigned char no_of_byte,unsigned char *string_data)
{
unsigned char i = 0;
add |=0x20;
send_char(add);
for (i = 0; i < no_of_byte ; i++)
{
send_char(*string_data+i);
}
}
#endif