同一IC:78F9234模拟SPI读外设数据
设置不同IO端口,P0和P3都无**确读入外设数据,设置为P2却能正确读写外设数据.其它程序不变.
时钟为1MHZ.所有 IO口未作其它用处.未加上拉电阻.
IO端口定义如下:
SCS IO口不变.
#define SCS_IO P12_bit.no3 //spi SCS
#define SCS_OUTPUT() PM12_bit.no3 = OUTPUT
#define SCS P12_bit.no3 //spi SCS
采用P0口时作数据口时,无**常读入.
/*
#define SCK_IO P0_bit.no0 //spi SCK
#define SCK_OUTPUT() PM0_bit.no0 = OUTPUT
#define SCK P0_bit.no0 //spi SCS
#define SDIO_IO P0_bit.no1 //spi SDIO Read and Wirte
#define SDIO_OUTPUT() PU0_bit.no1 = PULLUP_OFF; PM0_bit.no1 = OUTPUT //spi SDIO Wirte
#define SDIO_INPUT() PU0_bit.no1 = PULLUP_ON; PM0_bit.no1 = INPUT //spi SDIO Read
#define SDIO P0_bit.no1
采用P2口作数据口时,正常.
#define SCK_IO P2_bit.no0 //spi SCK
#define SCK_OUTPUT() PM2_bit.no0 = OUTPUT
#define SCK P2_bit.no0 //spi SCS
#define SDIO_IO P2_bit.no1 //spi SDIO Read and Wirte
#define SDIO_OUTPUT() PU2_bit.no1 = PULLUP_OFF; PM2_bit.no1 = OUTPUT //spi SDIO Wirte
#define SDIO_INPUT() PU2_bit.no1 = PULLUP_ON; PM2_bit.no1 = INPUT //spi SDIO Read
#define SDIO P2_bit.no1
采用P3口作数据口时,也无**常读入.
#define SCK_IO P3_bit.no3 //spi SCK
#define SCK_OUTPUT() PM3_bit.no3 = OUTPUT
#define SCK P3_bit.no3 //spi SCS
#define SDIO_IO P3_bit.no2 //spi SDIO Read and Wirte
#define SDIO_OUTPUT() PU3_bit.no2 = PULLUP_OFF; PM3_bit.no2 = OUTPUT //spi SDIO Wirte
#define SDIO_INPUT() PU3_bit.no2 = PULLUP_ON; PM3_bit.no2 = INPUT //spi SDIO Read
#define SDIO P3_bit.no2
IO初始化为:
SCS_OUTPUT();
SCS = 1;
SCK_OUTPUT();
SCK = 0;
SDIO_INPUT();
SDIO = 1;
读数据程序如下:
Uint8 ByteRead(void)
{
Uint8 i,tmp;
SDIO_INPUT ();
SDIO = 1; //sdio pull high
_nop_ ();
_nop_ ();
for(i = 0; i < 8; i++)
{
if(SDIO)
tmp = (tmp << 1) | 0x01;
else
tmp = tmp << 1;
SCK = 1;
_nop_();
SCK = 0;
}
_nop_ ();
_nop_ ();
return tmp;
}
写数据如下:
void ByteSend(Uint8 src)
{
Uint8 i;
SDIO_OUTPUT ();
_nop_ ();
for(i = 0; i < 8; i++)
{
if(src & 0x80)
SDIO = 1;
else
SDIO = 0;
_nop_();
SCK = 1;
_nop_();
SCK = 0;
src = src << 1;
}
_nop_();
_nop_();
SDIO_INPUT ();
}
无法理解.程序都 一样.为何是这样,是IC问题,还是....? |