write.c

来自「Source code for RFM01 fm radio receiver」· C语言 代码 · 共 23 行

C
23
字号
#include "../twi.h"

int TWI_write(unsigned char address, unsigned char *data, unsigned char bytes)
{
  while(TWI_stat & (1<<TWI_BUSY));  // Bus is busy wait (or exit with error code)
  while(TWCR & (1<<TWSTO));
  
  TWI_address = address;
  TWI_data = data;
  TWI_bytes = bytes;
  TWI_ddr = TW_WRITE;

  TWI_retry_cnt = 0;
  
  /* Generate start condition, the remainder of the transfer is interrupt driven and
     will be performed in the background */
  TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN)|(1<<TWIE);
  
  TWI_stat |= (1<<TWI_BUSY);
  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?