|
本帖最后由 南沟的水 于 2014-1-6 19:34 编辑
//stm32f050 hardware IIC send 256--510 Bytes
void MASTER2_Write(uint8_t* pBuffer,uint16_t NumByteToWrite)
{
uint8_t Num=255;
uint8_t NumOfSingle=NumByteToWrite-255;
/* Configue CR2 : Slave Address ,NBYTES, write request and RELOAD */
I2C1->CR2=SlaveAddress|(255<<16)|(0<<10)|(1<<24);
I2C1->CR2|=(1<<13);//START
while (Num--)
{
/* Wait until TXIS flag is set */
while(!(I2C1->ISR &(1<<1)));
/* Write data to TXDR */
I2C1->TXDR= *(pBuffer++);
}
// while(I2C1->ISR&(1<<6));
while(!I2C1->ISR&(1<<7));//TCR=1
Delay_ms(1);//????????????????????????????????????????????????????????????????????????????????????????????????????
/* Update CR2 : set Slave Address, ,NBYTES, write request and Autoend mode */
I2C1->CR2=SlaveAddress|(NumOfSingle<<16)|(1<<25);
while(I2C1->ISR&(1<<7));//TCR=0
while (NumOfSingle--)
{
/* Wait until TXIS flag is set */
while( !(I2C1->ISR &(1<<1)) );
/* Write data to TXDR */
I2C1->TXDR= *(pBuffer++);
}
/* Wait until STOPF flag is set */
while( !(I2C1->ISR &(1<<5)) );
/* Clear STOPF flag */
I2C1->ICR|=(1<<5);
}
这里我自己加了个延时,如果不加,就不能正常发送。为什么?不应该要加延时啊。
求教青风大哥
|
|