130 likes | 282 Views
MSP430 programming for serial interfacing with sensors. se. SPI. Master–Slave mode Synchronous protocol All transmissions are referenced to a common clock Clock generated by the master (MCU) Four main signals Master Out Slave In (MOSI): data from master to slave
E N D
SPI • Master–Slave mode • Synchronous protocol • All transmissions are referenced to a common clock • Clock generated by the master (MCU) • Four main signals • Master Out Slave In (MOSI): data from master to slave • Master In Slave Out (MISO): data from slave to master • Serial Clock (SCLK or SCK): clock • Chip Select (CS): select particular peripheral when multiple peripherals are connected to master
SHT11 • Relative humidity and temperature sensors • Digital output • Manufacturer defined interface • two wires bi-direction Use a GPIO pin as clock (SCK), it is always output direction Use another GPIO as DATA, dynamic setting it to input(read) or output(write) direction
Start Transmission and Send Command • How to start • What are the commands available
An Example: SHT11 Pull-up Data pin in output direction Set data pin to input direction, then SHT11 controls the DATA line • Timing diagram
Convert to Physical Values • 12-bit humidity, 14-bit temperature • Temperature • Humidity
Device Driver • Download here • http://nslab.ee.ntu.edu.tw/courses/wsn-labs-spring-09/labs/sht11Driver.rar • Important functions in SHT1x_sensirion.c • void sht1xInit(); • void sht1xReset(); • char sht1xMeasure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode); • void sht1xCalculate(float *p_humidity ,float *p_temperature);
Functions • char sht1xMeasure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode); • mode: { TEMP, HUMI } • Store measured value to *p_value • Store 8-CRC checksum to *p_checksum • void sht1xCalculate(float *p_humidity ,float *p_temperature); • Convert measured value to physical value • Put the measured value in *p_humidity, *p_temperature • Result will also place in *p_humidity, *p_temperature (overwrite)