GPRS Connection measuring temperature via SPI

Post your example source code and application notes to share with others
Post Reply
User avatar
Forrest
Posts: 287
Joined: Wed Apr 23, 2008 10:05 am

GPRS Connection measuring temperature via SPI

Post by Forrest »

Hello,

This is a draft of a new GPRS application/example. Corrections may be added.

NetBurner GPRS Application Note


What is GPRS

General Packet Radio Service (GPRS) is a form of wireless communication utilizing a cellular data connection. This data connection can be used to transmit and receive packets of data. While connected via GPRS, you can expect to get a data rate of 60-80 kbps. A GPRS connection is generally available anywhere that you can get cellular service.

Application Note Description

This application will demonstrate how to establish a mobile connection via GPRS and email data collected back to an email address.

The application begins by opening a GPRS connection to get a network address through the mobile data link. The application uses a small temperature sensor which reports the current temperature measured from the device every minute. Data is exchanged between the NetBurner module and the temperature sensor via an SPI connection. Over the course of one hour, the temperature readout is saved in a buffer. After one hour has past, the NetBurner module and emails the logged data to a specified email address. Once the email has been sent the module resumes collecting temperature data.

Parts List

Part Name
Part Code
Supplier
Price

NetBurner MOD5270LC Development Kit
NNDK-MOD5270LC-Kit
http://www.netburnerstore.com
$99

LM70 Temperature Sensor
LM70CIMM-3CT-ND
http://www.digikey.com
$1.98

GM862 Cellular Quad Band Module
CEL-00757
http://www.sparkfun.com
$99.95

GM862 Evaluation Board - Basic 50-Pin (Optional)
CEL-00277
http://www.sparkfun.com
$29.95

GM862 Evaluation Board - RS232 (Optional)
CEL-00477
http://www.sparkfun.com
$74.95


Connections


If you hook up the following lines to their specified ports, you should be able to duplication this example.

LM70 --> MOD5270

The LM70 temperature sensor should be connected to the MOD5270 QSPI lines.

SI/O --> SPI_DIN
SC --> SPI_CLK
~CS --> SPI_CS0
V+ --> VCC
GND --> GND


TELIT GM862 --> MOD5270

The GM862 will have a different connection set up depending on if you are using the 50-pin evaluation board, or are using the RS232 evaluation board.

The RS232 evaluation board is easier to set up, as it has an onboard power supply that will give you the 3.8V required input. Data is connected to the NetBurner MOD5270 through an RS232 serial cable.

The 50-pin evaluation board must be powered by 3.8V. The MOD5270LC kit does not supply this voltage, so you will need to provide 3.8V to the device. For a power indicator, you should supply an LED. The RS232 evaluation board includes an LED.

Connections that are only required for the 50-pin evaluation board will be marked (50pin) in the connection list. Connections required by the RS232 will be marked (RS232).

3.8V --> VCC (50pin) (You must supply 3.8V)
ON/OFF --> IRQ1
PWR_CTL --> LED (50pin)
RX --> UART1_TX (50pin)
TX --> UART1_RX (50pin)
GND --> GND (50pin)
DB9 --> UART1 (RS232)


Code Description

SPI Temperature Collection

The code to collect data from the thermometer is very simple. QSPI is initialized at boot time, and then is queried for the 2 bytes of temperature data every minute. A semaphore is used to tell the code to wait until the QSPI transfer is complete before continuing on in the code.

Code: Select all

	OS_SEM QSPI_SEM;
	OSSemInit(&QSPI_SEM, 0);
	QSPIInit(1000000, 11, 0xE, 1, 0, 1, TRUE,0x30, 0x30); 
The initialize code creates the semaphore and establishes connection parameters for sampling the thermometer.

Code: Select all

	short RawTempData = 0;
QSPIStart(NULL, (BYTE*) &RawTempData, 2, &QSPI_SEM);  // Receive data
	OSSemPend(&QSPI_SEM, 0); // Wait for QSPI to complete
The sampling code creates a buffer and then gets 2 bytes of data from the SPI line. The semaphore pend waits for the transfer to complete before continuing.


GPRS Connection

The GPRS connection is treated as a PPP connection, and uses the NetBurner PPP instructions to manage the connection. The GPRS is run from a task that monitors the GPRS link. If a link is lost, then program will attempt to reestablish that connection. All dialing, PPP commands, IP stack is handled by the NetBurner source that works without modification.

Code: Select all

iprintf("\r\nDialing...\r\n");
	int rv = DialPPP(SERIALPORT_TO_USE, &pppo, DIAL_STRING);
	if (rv != ERR_PPP_SUCCESS)
		ShowErrors("Dial Failed", rv);
	else {
		iprintf("Connection Established\r\n");
		EthernetIpGate = 0;
	}
	if (GetPPPState() != eOpen)
		OSTimeDly(TICKS_PER_SECOND * 5);
	while (GetPPPState() == eOpen && allDone == false) {
		GPRSLink = TRUE;
		OSTimeDly(3 * TICKS_PER_SECOND);
		iprintf("Active Connection, Secs:%d\r\n",Secs);
	}

	ClosePPPSesion();
	StopPPPDameon();
	GPRSLink = FALSE;
	iprintf("Disconnected from GPRS server.... \r\n");
	connectionCounter++;
The connection is established in this code. PPP options are set at this point. To see all PPP options that are set, please see the source attached to this document.

If the connection fails, the program will continue to try to redial until it successfully connects to the mobile network. If the connection is successful, the task sits and monitors the connection. At the first sign of failure, it will close the connection and redial to reestablish the link.


Sending the Collected Data via Email

Mail is sent from the NetBurner device every hour containing a log of the temperatures collected so far. No mail server login credentials are required, as we are acting as the mail server in this example. Please note, some mail clients may treat the email as spam, so you should white list the email reply address you are sending from.

Code: Select all

while (mailSent != 1) {
		mailSent = SendMailAsServer("email_address_from",
			"email_address_to",
			"subject", data);
		OSTimeDly(TICKS_PER_SECOND * 5);
	}
In this code, you should change the values email_address_from and email_address_to to valid email addresses. I recommend setting them to the same address. The reason for this is to help get the email through any spam guards that do not like that the from address may not be valid. Replying to this email is pointless, as the board cannot accept incoming email addresses.




Adding Functionality


This example is intended to provide a rudimentary connection example. To complete the project and turn it into a product to sell, added functionality in the Telit GPRS module should be taken advantage of. The ability to turn on and off the Telit through code should be added to the source. I would also recommend a way to disconnect from the GPRS mobile link when sampling data, as the mobile connection is not in use and is draining power.
Attachments
GPRSSource.zip
(4.55 KiB) Downloaded 1282 times
Forrest Stanley
Project Engineer
NetBurner, Inc

NetBurner Learn Articles: http://www.netburner.com/learn
v8dave
Posts: 333
Joined: Thu Dec 31, 2009 8:31 pm

Re: GPRS Connection measuring temperature via SPI

Post by v8dave »

Hi, I was wondering if you had been able to get the PPP connection to work on COM port 2?

I can't get it to work and currently investigating with support to why not.

I don't have a modem to try on COM1 so can't try if that works. My hardware is custom made and uses COM2 for the modem as COM1 is setup for CAN bus.

Cheers,
Dave...
v8dave
Posts: 333
Joined: Thu Dec 31, 2009 8:31 pm

Re: GPRS Connection measuring temperature via SPI

Post by v8dave »

What is the reason for this assignment?

EthernetIpGate = 0;


I am not seeing any gateway activity when I connect to the GPRS connection. If I plug in a network cable, I suddenly get communications via my network. Is this assignment required to cause the GPRS connection to work?

Thanks
Dave...
jamesmarie90
Posts: 1
Joined: Mon Mar 21, 2016 3:57 am

Re: GPRS Connection measuring temperature via SPI

Post by jamesmarie90 »

i, I was wondering if you had been able to get the PPP connection to work on COM port 2?

I can't get it to work and currently investigating with support to why not.

I don't have a modem to try on COM1 so can't try if that works. My hardware is custom made and uses COM2 for the modem as COM1 is setup for CAN bus.


Thanks for sharing this topic.
Noor
Post Reply