Reply
Posts: 1
Registered: ‎07-06-2017

EFM8SB1 total capacitance on multiple channels

Hello,

 

I'm new into Capacitive Sensing with the SleepyBee. My project is to measure capacitance and send the measured hex data (out of CS0DL and CS0DH) via SPI to a Computer.

 

Doing this with only one PIN works fine and i get no troubles (!)

 

But the next step is to measure the total capacitance of two (or more) pins and send the value the same way as mentioned above.

 

I enabled the multi channel Bit and set the PINs in CS0SCAN0 and CS0SCAN1. When i readout the CS0DL and CS0DH the value is 0 (zero). Why i don't get the total measured value?

 

Are there any more informations about multi channel and total capacitance? The information in the reference Manual didn't help me so far.

 

Some Parts of the SPI Interrupt are taken from the SPI examples for the EFM8.

 

//-----------------------------------------------------------------------------
// SB1_SPI0_Slave.c
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <si_toolchain.h>
#include <SI_EFM8SB1_Register_Enums.h>                  // SI_SFR declarations
#include "InitDevice.h"


//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------

SI_LOCATED_VARIABLE_NO_INIT (reserved, uint8_t, SI_SEG_XDATA, 0x0000);


//-----------------------------------------------------------------------------
// main() Routine
// ----------------------------------------------------------------------------
int main (void)
{
	//Enter default mode
	enter_DefaultMode_from_RESET();

	//enable the cap-sense module
	CS0CN0_CSEN = 1;

	//Select Start of Conversion Mode
	CS0CF = CS0CF_CS0CM__CS0BUSY;

	//multiple channel enable
	CS0CF = CS0CF_CS0MCEN__MULT_CHAN_ENABLED;

	//Selected CapSense Channel (Port 0)
	CS0SCAN0 = 00010000;

	//Selected CapSense Channel (Port 1)
	CS0SCAN1 = 00001000;

	//select 16-bit conversions
	CS0MD2 = CS0MD2_CS0CR__16_BITS;

	//make sure that the end-of-measurement interrupt flag is cleared
	CS0CN0_CSINT = 0;


	while (1)
	{
		CS0CN0_CSBUSY = 1;
		while(!CS0CN0_CSINT); CS0CN0_CSINT = 0;
	}
}
//=========================================================
// src/Interrupts.c: generated by Hardware Configurator
//
// This file will be regenerated when saving a document.
// leave the sections inside the "$[...]" comment tags alone
// or they will be overwritten!
//=========================================================


// USER INCLUDES
#include <SI_EFM8SB1_Register_Enums.h>

//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------

#define MAX_BUFFER_SIZE    8           // Maximum buffer Master will send

// Instruction Set
#define  SEND_CAP          0x08        // Send a byte from the Slave to the
                                       // Master
#define  SEND_TEMP  	   0x10        // Send a series of bytes from the Slave
                                       // to the Master
#define  ERROR_OCCURRED    0x40        // Indicator for the Slave to tell the
                                       // Master an error occurred

SI_SBIT (TEST_OUT, SFR_P0, 1);

//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------

uint8_t SPI_Data = 0xA5;

uint8_t SPI_Data_Array[MAX_BUFFER_SIZE] = {0};


//-----------------------------------------------------------------------------
// SPI0_ISR
//-----------------------------------------------------------------------------
//
// SPI0 ISR Content goes here. Remember to clear flag bits:
// SPI0CN0::MODF (Mode Fault Flag)
// SPI0CN0::RXOVRN (Receive Overrun Flag)
// SPI0CN0::SPIF (SPI# Interrupt Flag)
// SPI0CN0::WCOL (Write Collision Flag)
//
//-----------------------------------------------------------------------------
SI_INTERRUPT (SPI0_ISR, SPI0_IRQn)
{
	static uint8_t command;
	static uint8_t array_index = 1;
	static uint8_t state = 0;

	if (SPI0CN0_WCOL == 1)
	{
	  // Write collision occurred

	  SPI0DAT = ERROR_OCCURRED;        // Indicate an error occurred
	  SPI0CN0_WCOL = 0;                        // Clear the Write collision flag
	}
	else if (SPI0CN0_RXOVRN == 1)
	{
	  // Receive overrun occurred

	  SPI0DAT = ERROR_OCCURRED;        // Indicate an error occurred
	  SPI0CN0_RXOVRN = 0;                      // Clear the Receive Overrun flag
	}
	else
	{
	  // SPI0CN0_SPIF caused the interrupt

	  // Some commands are single-byte commands (SLAVE_LED_ON/SLAVE_LED_OFF)
	  // For multiple-byte commands, use the state to determine action
	  // <state> == 0: new transfer; a command is being received
	  // <state> == 1: writing/reading data
	  if (state == 0)
	  {
		 command = SPI0DAT;            // Read the command

		 array_index = 0;              // Reset the array index

		 switch (command)
		 {

			case SEND_CAP:

			   //CS0CN0_CSBUSY = 1;	   //initiate a capacitance measurement
			   	   	   	   	   	   	   // CS0CN0_CSINT wird nach Messung auf 1 gesetzt

			   SPI0DAT = CS0DH;        //Send CapSense High Byte
			   
			   SPI0DAT = CS0DL;		   //Send CapSense Low Byte
			   
			   state = 0;              // End of transfer (only one byte)

			   //CS0CN0_CSINT = 0;	   //clear Capsense Interrupt Flag

			   break;

			case SEND_TEMP:

				//SPI0DAT = Temperatur

				state = 0;

			   break;

			default:
			   state = 0;
		 }

	  }
	  else if (state == 1)
	  {
		 SPI_Data = SPI0DAT;
	  }

	  SPI0CN0_SPIF = 0;                        // Clear the SPI0CN0_SPIF flag
	}
}

Highlighted
Posts: 326
Registered: ‎09-22-2009

Re: EFM8SB1 total capacitance on multiple channels

Make sure your desired pins are set to analog mode for use with CS0. Also double-check your CS0SCAN values are what you want them to be.