Exemplo n.º 1
0
/*********************************************************************//**
 * @brief 		Main I2C0 interrupt handler sub-routine
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void I2C0_IRQHandler(void)
{
	done = I2C_MonitorHandler(LPC_I2C0,buffer,count);
	if(done)
	{
		I2C_MonitorModeConfig(I2CDEV,(uint32_t)I2C_MONITOR_CFG_MATCHALL, DISABLE);
		I2C_MonitorModeCmd(I2CDEV, DISABLE);
	}
}
Exemplo n.º 2
0
/**************************************************************************//**
 *
 * @brief  Applies the configuration data (comes from the client).
 *
 * @param [in] buff           Circular buffer to store captured data in
 * @param [in] cfg            Configuration to apply
 *
 * @retval CMD_STATUS_OK      If successfully configured
 * @retval CMD_STATUS_ERR_*   When the configuration could not be applied
 *
 *****************************************************************************/
cmd_status_t monitor_i2c_Configure(circbuff_t* buff, monitor_i2c_cfg_t* cfg)
{
  cmd_status_t result = CMD_STATUS_OK;

  pSampleBuffer = buff;

  validConfiguration = FALSE;

  do
  {
    if (cfg->clockrate <= 400000)
    {
      // Enable use of I2C buffer for max 400KHz
      LPC_GPIO_PORT->DIR[5] |= (1UL << 8);
      LPC_GPIO_PORT->SET[5] |= (1UL << 8);
    }
//     else if (cfg->clockrate <= 1000000)
//     {
//       // Enable use of I2C buffer for max 1MHz
//       if (pca9555_rawValues(CTRL_I2C_EN2, CTRL_I2C_EN1 | CTRL_I2C_EN2) != SUCCESS)
//       {
//         result = CMD_STATUS_ERR_MON_I2C_PCA95555_FAILED;
//         break;
//       }
//     }
    else
    {
      result = CMD_STATUS_ERR_MON_I2C_INVALID_RATE;
      break;
    }

    I2C_DeInit(LPC_I2C0);
    I2C_Init(LPC_I2C0, cfg->clockrate);
    I2C_Cmd(LPC_I2C0, ENABLE);
    LPC_I2C0->ADR0 = 0xc0;
    LPC_I2C0->ADR1 = 0xc1;

    /* Match all addresses and control the SCL output */
    I2C_MonitorModeConfig(LPC_I2C0, I2C_MONITOR_CFG_SCL_OUTPUT | I2C_MONITOR_CFG_MATCHALL, ENABLE);

    validConfiguration = TRUE;

  } while (FALSE);

  return result;
}
Exemplo n.º 3
0
int _I2C_MonitorModeConfig(uint8_t * args)
{
	uint8_t * arg_ptr;
	LPC_I2C_TypeDef* I2Cx;
	uint32_t MonitorCfgType;
	FunctionalState NewState;

	if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1;
	I2Cx = (LPC_I2C_TypeDef*) strtoul((char *) arg_ptr, NULL, 16);
	if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1;
	MonitorCfgType = (uint32_t) strtoul((char *) arg_ptr, NULL, 16);
	if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1;
	NewState = (FunctionalState) strtoul((char *) arg_ptr, NULL, 16);

	I2C_MonitorModeConfig(I2Cx, MonitorCfgType, NewState);
	return 0;
}
Exemplo n.º 4
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
	uint8_t idx,i;
	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	//print menu screen
	print_menu();

	/* I2C block ------------------------------------------------------------------- */

	/*
	 * Init I2C pin connect
	 */
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Funcnum = 1;
	PinCfg.Pinnum = 27;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);//SDA0
	PinCfg.Pinnum = 28;
	PINSEL_ConfigPin(&PinCfg);//SCL0

	// Initialize I2C peripheral
	I2C_Init(I2CDEV, 100000);

	/* Configure interrupt for I2C in NVIC of ARM core */
    /* Disable I2C0 interrupt */
    NVIC_DisableIRQ(I2C0_IRQn);
    /* preemption = 1, sub-priority = 0 */
    NVIC_SetPriority(I2C0_IRQn, ((0x01<<3)|0x01));
    //enable I2C interrupt
    I2C_IntCmd(LPC_I2C0, ENABLE);

	/* Enable I2C operation */
	I2C_Cmd(I2CDEV, ENABLE);

	while(1)
	{
		idx=0;count=0;
		while(idx<2)
		{
			if(idx==0)
			{
				_DBG_("\n\rEnter monitor buffer size: ");
			}
			idx++;
			switch(_DG)
			{
				case '0': count=(count<<4)|0x00;break;
				case '1': count=(count<<4)|0x01;break;
				case '2': count=(count<<4)|0x02;break;
				case '3': count=(count<<4)|0x03;break;
				case '4': count=(count<<4)|0x04;break;
				case '5': count=(count<<4)|0x05;break;
				case '6': count=(count<<4)|0x06;break;
				case '7': count=(count<<4)|0x07;break;
				case '8': count=(count<<4)|0x08;break;
				case '9': count=(count<<4)|0x09;break;
				case 'a': count=(count<<4)|0x0A;break;
				case 'A': count=(count<<4)|0x0A;break;
				case 'b': count=(count<<4)|0x0B;break;
				case 'B': count=(count<<4)|0x0B;break;
				case 'c': count=(count<<4)|0x0C;break;
				case 'C': count=(count<<4)|0x0C;break;
				case 'd': count=(count<<4)|0x0D;break;
				case 'D': count=(count<<4)|0x0D;break;
				case 'e': count=(count<<4)|0x0E;break;
				case 'E': count=(count<<4)|0x0E;break;
				case 'f': count=(count<<4)|0x0F;break;
				case 'F': count=(count<<4)|0x0F;break;
				default: idx=0;count=0;break;
			}
			if(idx==2)
			{
				if(count>BUFFER_SIZE)
				{
					_DBG_("invalid! The size is bigger than ");_DBH(BUFFER_SIZE);
					idx=0;count=0;
				}
				else
					_DBH(count);
			}
		}
		//Configure I2C in monitor mode
		I2C_MonitorModeConfig(I2CDEV,(uint32_t)I2C_MONITOR_CFG_MATCHALL, ENABLE);
		I2C_MonitorModeCmd(I2CDEV, ENABLE);

		_DBG_("\n\rStart monitoring I2C bus...");

		while(done==FALSE); done=FALSE;
		_DBG_("done!");
		for(i=0;i<count;i++)
		{
			if((i%16)==0) _DBG_("");
			_DBH(buffer[i]);_DBC(0x20);
			buffer[i]=0;
		}

	}
	return 1;
}