Update README.md

parent 70c18ad2
# Electronic Systems - Sistemas Eletrónicos
## Asynchronous communication system
## JTAG
### Description
* This system is composed of several nodes connected in master/slave architecture via UART;
* Each node uses a MAX485 differencial tranceiver;
* Each node has it's own address;
* The communication protocol uses 9 bits:
* 8 bits for tghe message to transmit;
* 1 bit to inform if it's an address or data (1 or 0 respectively);
* Master controls the LED's of each slave by pressing a button linked to a certain slave address;
* The main circuit is composed of:
* 1 ATmega 328p (and necessary peripheral components);
* 1 MAX485;
* 1 LED and resistor;
* 4 DIP switches to select the 4 bit address;
* 2 buttons to control the 2 slaves.
* This system is based around the ChipKIT Uno32 board and its JTAG capabilities;
* Arduino programmed as a JTAG controller;
* Serial communication to receive JTAG controls;
* Functionality to get ID code, turn on/off LED and read a button's state.
### Firmware implementation
`JTAGPort::begin()`:
* Setup TMS, TCK, TDO and TDI pins
* Reset JTAG state machine
* Setup TMS, TCK, TDO and TDI pins;
* Reset JTAG state machine;
* Doesn't return.
`void JTAGPort::reset()`:
* set TMS pin to HIGH.
* Do 5 clock Cycles to reach reset state on Jtag state machine.
* set TMS pin to HIGH;
* Do 5 clock Cycles to reach reset state on Jtag state machine;
* Doesn't return.
`void JTAGPort::clockPulse()`:
* Set TCK pin to HIGH.
* Wait 3 microseconds.
* Set TCK pin to LOW.
* Wait 3 microseconds.
* Set TCK pin to HIGH;
* Wait 3 microseconds;
* Set TCK pin to LOW;
* Wait 3 microseconds;
* Doesn't return.
`void JTAGPort::sendBits(uint8_t tms, uint8_t tdo)`:
* Set TMS pin to tms.
* Set TDO pin to tdo.
* Set TMS pin to TMS;
* Set TDO pin to TDO;
* Do a clock cycle.
* Doesn't return;
`void JTAGPort::sendBits(uint8_t tms, uint8_t tdo, uint8_t size)`:
* Sends tms and tdo bytes up to position size.
* Sends TMS and TDO bits up to position size.
`void JTAGPort::setDR()`:
* Set JTAG state machine to DATA SHIFT state.
`void JTAGPort::setIR()`:
* Reset JATG state machine.
* Reset JATG state machine;
* Set JTAG state machine to INTRUCTION SHIFT.
`void JTAGPort::sendInst(uint8_t instruction)`:
* Set JTAG state machine to INSTRUCTION SHIFT.
* Write chosen instruction.
* Set JTAG state machine to INSTRUCTION SHIFT;
* Write chosen instruction;
* Exit into JTAG state machine ready state.
`void JTAGPort::sendData(uint8_t tdo_pos, uint8_t value)`:
* Set JTAG state machine to DATA SHIFT state.
* Bit shift 0 into chosen pin Input register.
* Bit shift value into chosen pin Output register.
* Bit shift 1 into chosen pin Control register.
* Bit shift 1 into Reset.
* Set JTAG state machine to DATA SHIFT state;
* Bit shift 0 into chosen pin Input register;
* Bit shift value into chosen pin Output register;
* Bit shift 1 into chosen pin Control register;
* Bit shift 1 into Reset;
* Exit into JTAG state machine ready state.
`uint8_t JTAGPort::readData()`:
* Read from TDI pin.
* Shift data bit.
* Read from TDI pin;
* Shift data bit;
* return 1 if TDI pin is HIGH or 0 if LOW.
`uint8_t JTAGPort::readData(uint8_t tdo_pos)`:
* Set JTAG state machine to DATA SHIFT state.
* Send bits until reaching tdo_pos.
* Read TDI pin.
* Exit into JTAG state machine ready state.
* Set JTAG state machine to DATA SHIFT state;
* Send bits until reaching tdo_pos;
* Read TDI pin;
* Exit into JTAG state machine ready state;
* return 1 if TDI pin is HIGH or 0 if LOW.
`uint32_t JTAGPort::getID()`:
* Set intruction to IDCODE.
* Set JTAG state machine to DATA SHIFT state.
* Read TDI and bitshift readings into value.
* Exit into JTAG state machine ready state.
* Set intruction to IDCODE;
* Set JTAG state machine to DATA SHIFT state;
* Read TDI and bitshift readings into value;
* Exit into JTAG state machine ready state;
* return value.
`void JTAGPort::setLED(uint8_t value)`:
* Set Intruction to EXTERNAL TEST.
* Set Intruction to EXTERNAL TEST;
* Write 1 to LED pin register.
`uint8_t JTAGPort::checkButton()`:
* Set Instruction to SAMPLE AND PRELOAD.
* Read button pin register.
* Set Instruction to SAMPLE AND PRELOAD;
* Read button pin register;
* return value read.
`void setup()`:
* Start JTAG library;
* Start Serial port;
* Print commands.
`void loop()`:
* Checks if theres any command available in the Serial port:
* If command 'd', get and print ID code in hexadecimal;
* If command '1', turn on LED;
* If command '0', turn off LED;
* If command 'b', check button state.
### Firmware test
* Clone this repository with `git clone https://git.fe.up.pt/up201808899/sele_a2_b01_jtag.git`;
* Compile the *main.cpp* file with PlatformIO to get *.hex* file;
* Flash the *.hex* file to the master and slaves.
###### lixo
`void asynch9_init()`:
* Setup the baud rate;
* Set master as transmiter and slave as receiver;
* Set slave in multiprocessor mode;
* Set 9 bit frame.
* Doesn't return.
`uint8_t send_addr(uint8_t toSend)`:
* Wait for the transmit buffer to be clear;
* Set 9th bit to 1 to inform it is an address;
* Send target slave address set in *toSend*;
* Returns 1 if successful;
`uint8_t send_data(uint8_t toSend)`:
* Wait for the transmit buffer to be clear;
* Set 9th bit to 0 to inform it is data;
* Send target slave the new LED state.
* Return 1 if successful;
`uint8_t get_data()`:
* Check if it has any transmition errors. Return 0 if it has errors;
* Check the 9th bit:
* If 1, means is address:
* If it is the slaves address, turn off multiprocessor mode. If not, turn on multiprocessor mode.
* If 0, means is data:
* If data is 0, turn off LED. If data is 1, turn on LED;
* Returns 0 if successful;
### Schematic
`void setup()`:
* Set address pins and buttons pins as inputs with internal pullup resistors;
* Set LED and Write Enable (WREN) pins as outputs;
* Set WREN to 1 if master and 0 if slave;
![Schematic](https://image.easyeda.com/histories/42ce4c2fad8947d1a3f30718ed6f3c01.png)
`void loop()`:
* Runs infinitely, separating the code for the master and for the slave:
* Master:
* If button 1 changed state:
* Send address if last "contacted" slave was a different slave. If it was the same slave, don't send address;
* Send data (state of the button);
* If button 2 changed state:
* Send address if last "contacted" slave was a different slave. If it was the same slave, don't send address;
* Send data (state of the button);
* Slave:
* Check if receive buffer is full. If it is, get data.
### PCB layout
![Pcb](https://image.easyeda.com/histories/5b2d65338e8f468fa396a43fa75c85d7.png)
### Firmware test
* Clone this repository with `git clone https://git.fe.up.pt/up201808899/asynch9_a2_b01.git`;
* Compile the *main.cpp* file with PlatformIO to get *.hex* file;
* Flash the *.hex* file to the master and slaves.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment