Download Project Record Version 3 – 11/28/16 Serial

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Time-to-digital converter wikipedia , lookup

Flip-flop (electronics) wikipedia , lookup

Telecommunications engineering wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Transcript
Project Record
Version 3 – 11/28/16
Serial Communication Research
Pumpminder
Shawn Bordner
Project Record: Version 3 - 11/28/2016
ABSTRACT
After researching the 3 different types of serial communication available on our pic, we will
be using an UART protocol rather than the I2C and the SPI. We hope that this form of serial
communication will be able to provide the needed communication between the two pics: one
on the pump module and one on the display module through a typical CAT5 connection.
This record also shows example code for the UART initialization and the send methods with
the correct registers for a PIC16F1509.
VERSION HISTORY
Version
Author(s)
Date
Description
File Name
1
Shawn
Bordner
11/3/16
Initial MVP goals created.
Serial Communication
Research
2
Shawn
Bordner
11/14/16
Completed Research
Serial Communication
Research
3
Shawn
Bordner
11/28/16
Abstract Updated
Serial Communication
Research
Page 2 of 8
Project Record: Version 3 - 11/28/2016
Goal of Study
Questions to be answered by next MVP.
1. What are the different types of serial communication?
2. How complicated is it to code for the pic?
3. What information needs to be clearly communicated to the electronics team?
4. Why are we going to choose serial communication?
Journal
Synchronous vs Asynchronous Communication:
When using the synchronous communication, the information is transmitted from the
transmitter to the receiver. This means that both the transmitting and receiving end are set up
with a synchronized clock frequency. This frequency can however can be set through bit
registers or in some protocols there requires an additional wire for the clock. This type of
communication is faster in comparison to asynchronous since it is constantly transmitting the
information. This may not be desired for the idea that we want low power consumption when
trying to talk between the two pics.
When using the asynchronous communication, the transmitter and the receiver refraining
to transmit long sequences of bits because there isn't a full synchronization between the
transmitter, that sends the data, and the receiver, that receives the data. In asynchronous
communication there information is divided into bytes or 8 bits of information that then has 1
start bit, marking the beginning of the new part of information, and 1 stop bit marking the end
of the information. This type of communication allows for information to not be transmitting
at equal time, since they are independent of the clock. Thus maybe this form of
communication will provide us with the lower power consumption for the PIC.
SPI:
Serial Peripheral Interface is used from moving data simply and quickly from one device
to another. This is a synchronous type of serial communication and which there is a
Master-Slave relationship between the two devices. This means one device (master) has the
power to initiate communication with a slave device. The master provides a clock signal to
provide synchronization then the clock signal controls when data can change and when it is
valid for reading. This is another form of bidirectional full duplex communication.
I2C:
I2C stands for Inter-Integrated Circuit Communications. This type of communication is
implemented by a Master Synchronous Serial Port, known as the MSSP module. This module
needs to be build into the PIC micro in order for this to be used. This is also a synchronous
Page 3 of 8
Project Record: Version 3 - 11/28/2016
protocol that allows a master device to initiate communication with a slave device. Data is
exchanged between these devices in a bi directional form of communication. Since I2C is
synchronous, it has a clock pulse along with the data. This however is not full duplex form of
communication so we will not be choosing I2C.
USART:
USART which stands for Universal Synchronous Asynchronous Receiver Transmitter is a
common type of component for serial communication in the PIC microcontrollers. In order to
set up the communication we must set different parameters with the TXSTA transmit register
and RCSTA receive register.
http://www.microcontrollerboard.com/support-files/txsta-register.pdf
http://www.microcontrollerboard.com/support-files/rcsta-register.pdf
On our pic (PIC24F16KA101) however there is 4 pins that are used for the UART
communication.
Function
Pin
number
Input/Output
Description
U1CTS
12
I
UART1 Clear to Send Input
U1RX
6
I
UART1 Receive
U1TX
11
O
UART1 Transmit Output
U1RTS
13
O
UART1 Request to Send Output
UART uses a single data line for transmitting and one for receiving data. Most often 8-bit
data is transferred, as follows: 1 start bit(low level), 8 data bits and 1 stop bit(high level). The
low level start bit and high level stop bit mean that there's always a high to low transition to
start the communication. No voltage level, so you can have it at 3.3 V or 5 V, whichever your
microcontroller uses. Note that the microcontrollers which want to communicate via UART
have to agree on the transmission speed, the bit-rate, as they only have the start bit's falling
edge to synchronize.
Conclusion
After researching these 3 different types of serial communication for our pic
(PIC24F16KA101), we are going to implement the UART serial communication in order to
communicate between the two pic systems. We are choosing a serial communication so then
we are able to reduce the number of wires between both the pump module and the display
module. Also, we are adding a pic to our display module rather than having a passive display.
We will be able to have the display module interpret the messages from the pump module and
use only 4 wires to display to the LCD rather than 8. Also we will be able to use the
additional connection wires for battery indication and push button. According to research in
Page 4 of 8
Project Record: Version 3 - 11/28/2016
the references, UART seems to be the most commonly used protocol with this least amount
of troubles. We should be able to simply modify this given code for our pic.
Reference Example Code
// PIC16F1509 Configuration Bit Settings
#include <xc.h>
// CONFIG1
#pragma config FOSC = INTOSC
// Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN
pin)
#pragma config WDTE = OFF
// Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF
// Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON
// MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF
// Flash Program Memory Code Protection (Program memory code
protection is disabled)
#pragma config BOREN = ON
#pragma config CLKOUTEN = OFF
// Brown-out Reset Enable (Brown-out Reset enabled)
// Clock Out Enable (CLKOUT function is disabled. I/O or oscillator
function on the CLKOUT pin)
#pragma config IESO = ON
// Internal/External Switchover Mode (Internal/External Switchover Mode
is enabled)
#pragma config FCMEN = ON
// Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
// CONFIG2
#pragma config WRT = OFF
// Flash Memory Self-Write Protection (Write protection off)
#pragma config STVREN = ON
// Stack Overflow/Underflow Reset Enable (Stack Overflow or
Underflow will cause a Reset)
#pragma config BORV = LO
// Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor),
low trip point selected.)
#pragma config LPBOR = OFF
// Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = ON
// Low-Voltage Programming Enable (Low-voltage programming
enabled)
#define STRLEN 12
Page 5 of 8
Project Record: Version 3 - 11/28/2016
volatile unsigned char t;
volatile unsigned char rcindex;
volatile unsigned char rcbuf[STRLEN];
void USART_init(){
TXSTAbits.TXEN = 1;
// enable transmitter
TXSTAbits.BRGH = 1;
// high baud rate mode
RCSTAbits.CREN = 1;
// enable continuous receiving
// configure I/O pins
ANSELBbits.ANSB5 = 0;
// RX input type is digital
TRISBbits.TRISB5 = 1;
// RX pin is input
TRISBbits.TRISB7 = 1;
// TX pin is input (automatically configured)
SPBRGL = 25;
// set baud rate to 9600 baud (4MHz/(16*baudrate))-1
PIE1bits.RCIE = 1;
// enable USART receive interrupt
RCSTAbits.SPEN = 1;
// enable USART
}
void USART_putc(unsigned char c){
while (!TXSTAbits.TRMT);
// wait until transmit shift register is empty
TXREG = c;
// write character to TXREG and start transmission
}
void USART_puts(unsigned char *s){
while (*s){
USART_putc(*s);
// send character pointed to by s
s++;
// increase pointer location to the next character
}
}
int main(){
OSCCONbits.IRCF = 0x0D; // INTOSC frequency 4MHz
Page 6 of 8
Project Record: Version 3 - 11/28/2016
USART_init();
USART_puts("Init complete!\n");
INTCONbits.PEIE = 1;
// enable peripheral interrupts
INTCONbits.GIE = 1;
// enable interrupts
while(1){
}
return 0;
}
void interrupt ISR(void){
if (PIR1bits.RCIF){
// check if receive interrupt has fired
t = RCREG;
// read received character to buffer
// check if received character is not new line character
// and that maximum string length has not been reached
if ( (t != '\n') && (rcindex < STRLEN)){
rcbuf[rcindex] = t; // append received character to string
rcindex++;
// increment string index
}else{
rcindex = 0;
USART_puts(rcbuf);
// reset string index
// echo received string
}
PIR1bits.RCIF = 0;
// reset receive interrupt flag
}
}
References
UART - http://www.microcontrollerboard.com/pic_serial_communication.html
Page 7 of 8
Project Record: Version 3 - 11/28/2016
SPI - http://ww1.microchip.com/downloads/en/devicedoc/spi.pdf
I2C - http://ww1.microchip.com/downloads/en/DeviceDoc/i2c.pdf
Page 8 of 8