发送:
void MCUSPI_WRITE_ADDRESS_DATA(unsigned char data)
{unsigned char i=0;ENABLE_SPI_CS();//????????_delay(10);DISABLE_SPI_CS();Master(data);ENABLE_SPI_CS();//???????? _delay(10);}
void Master(unsigned short Data)
{ unsigned short temp=0b10000000;Master_SDO_DATC=0;//数据线输出Master_SCK=0;do{ Master_SDO_DAT=Data & temp; //Set SDO StateMaster_SCK=1; _delay(3); Master_SCK=0; //Generate SCK Clocktemp>>=1; //Next Bit} while (temp!=0);Master_SDO_DAT=0;Master_SCK=0;
}
void SPI_INIT(void){_cp0c=0x08; _cp1c=0x08; //MCU做主机的配置Master_SPIENC=0;Master_SDO_DATC=0;Master_SDI_DATC=0;Master_SCKC=0; }
void main()
{InitPowerOn();SPI_INIT();PAUSE(300);while(1){#if 1if(1==usbpower_flag){UsbPowerOn();}else{UsbPowerOff();}if(1==buttonpower_flag){ButtonPowerOn();}else{ButtonPowerOff();}//Key_record();//Key_audio();#endif//enter_sleep();//MCUSPI_WRITE_ADDRESS_DATA(0xa3);//SPI_WRITE_ADDRESS_DATA(0x1e,0x40);MCUSPI_WRITE_ADDRESS_DATA(0xb4);}
}
接收:
void rtc_mcu_spi_init(void)
{printk("---------rtc_mcu_spi_init--------------\n");gpio_config(MCU_SPI_EN, GPIO_FUNC_SW_INPUT);gpio_config(MCU_SPI_MISO, GPIO_FUNC_SW_INPUT);gpio_config(MCU_SPI_MOSI, GPIO_FUNC_SW_OUTPUT);gpio_config(MCU_SPI_SCL, GPIO_FUNC_SW_INPUT);gpio_set(MCU_SPI_EN);gpio_clr(MCU_SPI_SCL);gpio_set(MCU_SPI_MISO);gpio_set(MCU_SPI_MOSI);//spi_config(MCU_SPI_ID, MCU_SPI_MODE, MCU_SPI_DFS, MCU_SPI_BAUD_RATE);//spi_master_config(SPI_MASTER2, 0, MCU_SPI_MODE, MCU_SPI_DFS, MCU_SPI_BAUD_RATE);//spi_config_ena_pin_polarity(SPI_MASTER2, 0, SPI_CS_POL_HIGH);
}void rtc_mcu_spi_handler(int eid)
{u16 reg;u16 data[2];u16 dat[2];unsigned char i;unsigned char dataspi;while(!gpio_val(MCU_SPI_EN));//一开始就是0、得等一下while(gpio_val(MCU_SPI_EN)); if(!gpio_val(MCU_SPI_EN)){ //if tha MCU_SPI_EN is low do for(i = 0; i <8; i ++){ dataspi |= gpio_val(MCU_SPI_MISO);if(i<7){while(gpio_val(MCU_SPI_SCL));while(!gpio_val(MCU_SPI_SCL)); }dataspi <<= 1;} }printk("======dat[0]===========:%d, %x\n",dataspi,dataspi); }
//weiqifartc_mcu_spi_init();app_timer_register(TIMER_1HZ, rtc_mcu_spi_handler);
搞了一天、模拟的话感觉有点眉头了、如果用ITRON系统里的API搞不出来、那后面可能还是要用模拟的、
安霸这个鸟系统、BUG真他妈多