ATMEGA16 SPI双机通讯问题
时间:10-02
整理:3721RD
点击:
在测试简单的SPI双机通讯程序的时候
1.主机、从机程序全部用IAR编辑时候 仿真无任何变化
2.主机、从机程序全部用ICC编辑时候 仿真有反应但是输出结果错误
3.主机用IAR编辑,从机用ICC编辑 仿真完全正常
请问出现这种情况的原因是什么?
主机程序(IAR)
#include"iom16.h"#define uint unsigned int#define uchar unsigned char#define SPIF 8#define DD_SS 4#define DD_SCK 7#define DD_MOSI 5#define SPE 6#define SPR0 1#define MSTR 4uchar temp=0;//uchar dat[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};void SPI_ADMINPORT_INIT(){ DDRB=(1<<DD_SS)|(1<<DD_MOSI)|(1<<DD_SCK); SPCR=(1<<SPE)|(1<<SPR0)|(1<<MSTR);}
void SPI_transmit(uchar data){ SPDR=data; while(!(SPSR&(1<<SPIF)));}void main(){ DDRC=0XFF; SPI_ADMINPORT_INIT(); SPI_transmit(0x4F);}
从机程序(icc)#include"iom16v.h"#define uint unsigned int#define uchar unsigned #define DD_MISO 6void SPI_ADMINPORT_INIT(){ DDRB=(1<<DD_MISO); SPCR=(1<<SPE)|(1<<SPR0);}uchar SPI_RECE(){ while(!(SPSR&(1<<SPIF))); return SPDR;}void main(){ DDRC=0XFF; DDRD=0XFF; SPI_ADMINPORT_INIT(); PORTC=0XFF; PORTD=SPI_RECE();}
1.主机、从机程序全部用IAR编辑时候 仿真无任何变化
2.主机、从机程序全部用ICC编辑时候 仿真有反应但是输出结果错误
3.主机用IAR编辑,从机用ICC编辑 仿真完全正常
请问出现这种情况的原因是什么?
主机程序(IAR)
#include"iom16.h"#define uint unsigned int#define uchar unsigned char#define SPIF 8#define DD_SS 4#define DD_SCK 7#define DD_MOSI 5#define SPE 6#define SPR0 1#define MSTR 4uchar temp=0;//uchar dat[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};void SPI_ADMINPORT_INIT(){ DDRB=(1<<DD_SS)|(1<<DD_MOSI)|(1<<DD_SCK); SPCR=(1<<SPE)|(1<<SPR0)|(1<<MSTR);}
void SPI_transmit(uchar data){ SPDR=data; while(!(SPSR&(1<<SPIF)));}void main(){ DDRC=0XFF; SPI_ADMINPORT_INIT(); SPI_transmit(0x4F);}
从机程序(icc)#include"iom16v.h"#define uint unsigned int#define uchar unsigned #define DD_MISO 6void SPI_ADMINPORT_INIT(){ DDRB=(1<<DD_MISO); SPCR=(1<<SPE)|(1<<SPR0);}uchar SPI_RECE(){ while(!(SPSR&(1<<SPIF))); return SPDR;}void main(){ DDRC=0XFF; DDRD=0XFF; SPI_ADMINPORT_INIT(); PORTC=0XFF; PORTD=SPI_RECE();}
按理说应该不会出现这种问题的