Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- adimmit
- Date:
- 2021-10-20
- Revision:
- 0:63fac75e5afc
- Child:
- 1:466049963f1f
File content as of revision 0:63fac75e5afc:
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
#include "platform/mbed_thread.h"
#include <SPI.h>
//SETUP THE LTC CHIP
#define LTC_MOSI PB_2
#define LTC_MISO PC_11
#define LTC_CLK PC_10
#define LTC_CS PA_15
#define BSY PB_5
#define CNV PB_6
#define DATA_LEN 144 //bits of data we will transmit 6-ch 24 bits/ch
#define BUFF_SIZE 9 // 9, 16-bit words will come through
SPI LTC_CHIP(LTC_MOSI, LTC_MISO, LTC_CLK);
DigitalOut cs_LTC(LTC_CS);
DigitalIn bsy_LTC(BSY);
DigitalOut CNV_PIN(CNV);
//SETUP REGISTERS
uint16_t rx_buff[DATA_LEN]; //want to read 144 bits (literally bits)
//setup SERIAL
Serial pc(USBTX, USBRX);
/*
We need to
- pull CS low
- read the data into a register
- release CS
- decode the data
- repeat
*/
void read_data() {
//request conversion
CNV_PIN=1;
wait_us(60);
CNV_PIN=0;
//WAIT FOR BSY --> bsy_LTC
//while(bsy_LTC==1){}
//then ask for data
//cs_LTC=0;
//spi id register
//LTC_CHIP.write(0x00); // --> do we need this?
//read 144 bytes
/*
int bytecount = 0;
while(bytecount < BUFF_SIZE){
rx_buff[bytecount] = LTC_CHIP.write(0x00);
bytecount++;
}
*/
//lift CS
//cs_LTC=1;
//WRITE THIS TO A STRUCT OF SOME SORT but we need to delete the bits we don't care about
}
int main()
{
// Initialise the digital pin LED1 as an output
DigitalOut led(LED1);
cs_LTC=0;
CNV_PIN=0;
//setup pc
pc.baud(115200);
pc.printf("------STARTUP------\n\n\n");
//setup SPI
LTC_CHIP.format(16, 0);
LTC_CHIP.frequency(1000000); //60Mhz clock frequency
while (true) {
//read and print data to serial terminal
read_data();
//print the spi bytes
/*
pc.printf("first int: %d\n", rx_buff[0]); //just check the first "word" for now b/c it should be correct
pc.printf("second int: %d\n", rx_buff[1]);
pc.printf("third int: %d\n", rx_buff[2]);
pc.printf("fourth int: %d\n", rx_buff[3]);
pc.printf("fifth int: %d\n", rx_buff[4]);
pc.printf("sixth int: %d\n", rx_buff[5]);
pc.printf("seventh int: %d\n", rx_buff[6]);
pc.printf("eight int: %d\n", rx_buff[7]);
*/
//wait for 1 second
wait(1);
}
}
