#include #include "Arduino.h" #include #define FIRSTCHANNEL 15 const int chipSelectPin = 10; volatile int16_t channel_data[10000] = {0}; //int8_t recieve_data[20000]; volatile int8_t buff[20000] = {0}; void setup() { // put your setup code here, to run once: SPI.begin(); //Initialize SPI bus unsigned int timecnt; pinMode(chipSelectPin, OUTPUT); //Set the chipSelectPin to be an output on the Arduino Serial.begin(9600); //Initialize the serial monitor to monitor at 9600 Baud SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0)); //Set Arduino's SPI settings to match those of the RHD2000 chip - max clock speed of 8 MHz, data transmitted most-significant-bit first, and mode 0: clock polarity = 0, clock edge = 1 delay(250); timecnt = micros(); for(int i=0;i<10000;i++){ channel_data[1] = SendConvertCommand(FIRSTCHANNEL); } timecnt = micros() - timecnt; Serial.print("round-robin timecnt= "); Serial.print(timecnt/1000); // 27ms ~8MHz Serial.println("ms"); delay(250); timecnt = micros(); SPI.transfer(&buff ,sizeof(buff)); timecnt = micros() - timecnt; Serial.print("one calling timecnt= "); Serial.print(timecnt/1000); // 21ms ~8MHz Serial.println("ms"); } void loop() { // put your main code here, to run repeatedly: } uint16_t SendConvertCommand(uint8_t channelnum) { //Sends a CONVERT command to the RHD chip through the SPI interface //The channelnum is the channel number that is desired to be converted. When a channel is specified, the amplifier and on-chip ADC send the digital data back through the SPI interface uint16_t mask = channelnum << 8; mask = 0b0000000000000000 | mask; //digitalWrite(chipSelectPin, LOW); uint16_t out = SPI.transfer16(mask); //digitalWrite(chipSelectPin, HIGH); return out; }