/*
** ===================================================================
**     Method      :  I2C1_SendChar (bean InternalI2C)
**
**     Description :
**         When working as a MASTER, this method writes one (7-bit
**         addressing) or two (10-bit addressing) slave address
**         bytes inclusive of R/W bit = 0 to the I2C bus and then
**         writes one character (byte) to the bus. The slave address
**         must be specified before, by the "SelectSlave" or
**         "SelectSlave10" method or in the bean initialization
**         section, "Target slave address init" property. If
**         interrupt service is enabled and the method returns
**         ERR_OK, it doesn't mean that transmission was successful.
**         The state of transmission is obtainable from
**         (OnTransmitData, OnError or OnArbitLost) events. 
**         When working as a SLAVE, this method writes a character
**         to the internal output slave buffer and, after the master
**         starts the communication, to the I2C bus. If no character
**         is ready for a transmission (internal output slave buffer
**         is empty), the Empty character will be sent (see "Empty
**         character" property).
**     Parameters  :
**         NAME            - DESCRIPTION
**         Chr             - Character to send.
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_DISABLED -  Device is disabled
**                           ERR_BUSY - The slave device is busy, it
**                           does not respond by an acknowledge (only
**                           in master mode and when interrupt
**                           service is disabled)
**                           ERR_BUSOFF - Clock timeout elapsed or
**                           device cannot transmit data
**                           ERR_TXFULL - Transmitter is full (slave
**                           mode only)
**                           ERR_ARBITR - Arbitration lost (only when
**                           interrupt service is disabled and in
**                           master mode)
** ===================================================================
*/
unsigned char I2C1_SendChar(unsigned char Chr)
{
  if((IBSR_IBB)||(InpLenM)||(I2C1_SerFlag&(CHAR_IN_TX|WAIT_RX_CHAR|BUSY))) { /* Is the bus busy */
    return ERR_BUSOFF;                 /* If yes then error */
  }
  ChrTemp = Chr;                       /* Save character */
  return (I2C1_SendBlock(&ChrTemp, (unsigned short)1, (unsigned short*)&I2C1_SndRcvTemp)); /* Send character and return */
}
Example #2
0
void I2C_OnTxChar(void) {
  /* request to send a character, this is a read from the memory */
  word nof;
  uint8_t data;

  dbgF(I2C_DEBUG_TxChar);
  if (memDevice.addr<sizeof(memDevice.u)) {
    data = memDevice.u.mem[memDevice.addr];
    memDevice.addr++; /* increment address counter */
  } else {
    data = 0xFF; /* undefined data */
  }
  (void)I2C1_SendBlock(&data, 1, &nof);
}
Example #3
0
void I2C_SendCmd(void) {
  if (sendCmd) {
#if PL_HAS_UI
    word snt;
    char buf[32];

#if PL_HAS_RUNNER
    buf[0] = '@';
    buf[1] = '\0';
    RUNNER_GetCmdString(buf, sizeof(buf));
#else
    SLIDER_GetCmdString(buf, sizeof(buf));
#endif
    (void)I2C1_SendBlock(buf, sizeof(buf), &snt);
#endif /* PL_HAS_UI */
    sendCmd = FALSE;
  }
}
Example #4
0
void I2C_OnReadReq(void) {
  /* called by a master 'read' request on the bus */
  /* Write[@]+ACK
   * addr+ACK
   * Read[@]+ACK  <<= we are here!
   * data at mem[addr]  << Send this data
   */
  word nof;
  uint8_t data;

  dbgF(I2C_DEBUG_ReadReq);
  if (memDevice.addr<sizeof(memDevice.u)) {
    data = memDevice.u.mem[memDevice.addr];
    memDevice.addr++; /* increment address counter */
  } else {
    data = 0xFF; /* undefined byte */
  }
  (void)I2C1_SendBlock(&data, 1, &nof);
}