Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #30 on: September 02, 2012, 11:58:03 pm » |
The Arduino has an 8-bit SPI peripheral and therefore only transmits 8 bits at a time.
However you can just transmit two bytes in a row, the end result is the same.
______ Rob
Thanks a lot Sir for your kind reply. I have done like this only , I am sending SPI.transfer(0x3B); SPI.transfer(0x2C); together in a row, and I am happy that it is transmitting both the data and generating 16 clock cycles on Oscilloscope but Sir, between these two consecutive 8 bit data there is a gap or delay on the Oscilloscope. So, for implementation like IMU(ADIS16405) chip where we need to send 16 bit command, how it will work. The gap/delay between these two 8 bit data will be considered as 0. Please suggest something on this. Thanks & Regards..... :-)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #31 on: September 03, 2012, 01:41:42 am » |
The gap/delay between these two 8 bit data will be considered as 0. No it won't because the receiving device only clocks in bits on the clock pulses. There is no "clocked" gap.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #32 on: September 03, 2012, 05:13:00 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #33 on: September 03, 2012, 07:19:09 am » |
The gap/delay between these two 8 bit data will be considered as 0. No it won't because the receiving device only clocks in bits on the clock pulses. There is no "clocked" gap. Thanks a lot Sir, for your kind reply. Thanks & Regards... :-)
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #34 on: September 06, 2012, 05:40:02 am » |
Respected Sir After receiving data as data[1] = Slave_receive(); data[2] = Slave_receive(); which are suppose 0x3b and 0x34, Can we concatenate this and display as 0x3b34 on Serial.println(data , HEX); is it possible to do this.
I am getting two separate data as 0x3b and 0x34 but want to display together as 0x3b34.
Can you please guide me how to do this.
Thanks and Regards...!!!
|
|
|
|
« Last Edit: September 06, 2012, 05:47:38 am by ranjeetray »
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 71
Posts: 6803
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #35 on: September 06, 2012, 06:07:30 am » |
Serial.println((data[1] << 8 ) + data[2], HEX);
______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #36 on: September 06, 2012, 06:24:51 am » |
Serial.println((data[1] << 8 ) + data[2], HEX);
______ Rob
Respected Sir Thanks a Ton. it is working. You are mind blowing Sir. Thanks & Regards...... 
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 71
Posts: 6803
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #37 on: September 06, 2012, 08:56:08 am » |
We aim to please  (if possible) _____ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #38 on: September 27, 2012, 02:34:12 am » |
The gap/delay between these two 8 bit data will be considered as 0. No it won't because the receiving device only clocks in bits on the clock pulses. There is no "clocked" gap. Respected Sir Why this following code is not generating 16 clock cycle continuously. Here I am using two continuous SPI.transfre(); but it is not giving 16 clock cycle. #include <SPI.h>
#define SCK_PIN 13 #define MISO_PIN 12 #define MOSI_PIN 11 #define SS_PIN 10
unsigned char data; int array[6] = {0x0A04, 0x0107, 0x0E05, 0x0209, 0x0B08, 0x0507 }, ii;
void SlaveInit(void) { // Set MISO output, all others input pinMode(SCK_PIN, INPUT); pinMode(MOSI_PIN, INPUT); pinMode(MISO_PIN, OUTPUT); pinMode(SS_PIN, INPUT);
// Enable SPI SPCR = B00101100; SPCR = (1<<SPE); }
void setup(){ Serial.begin(9600); SPI.begin(); //SPI.setDataMode(SPI_MODE2); //SPI.setBitOrder(LSBFIRST); }
void loop() { unsigned char hg = 0; Serial.println("Data Received from Master Board"); SlaveInit(); data = SPI_SlaveReceive(); Serial.println(data, HEX); hg = data; data = 0; if(hg == 0x3B) { Serial.println("Writting Data on SPI bus"); pinMode(SS_PIN, OUTPUT); digitalWrite(SS_PIN, LOW); SPI.transfer(0x3b); SPI.transfer(0x2b); digitalWrite(SS_PIN, HIGH); Serial.println(); Serial.println("Sending Done"); delay(10); }
}
unsigned char SPI_SlaveReceive() { while(!(SPSR & (1<<SPIF))); return SPDR; }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #39 on: September 27, 2012, 05:33:49 am » |
Why this following code is not generating 16 clock cycle continuously. Here I am using two continuous SPI.transfre(); but it is not giving 16 clock cycle.
Prove it. Where is your logic analyzer output?
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 71
Posts: 6803
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #40 on: September 27, 2012, 06:00:50 am » |
but it is not giving 16 clock cycle. How do you know that? ______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #41 on: October 02, 2012, 10:21:53 pm » |
but it is not giving 16 clock cycle. How do you know that? ______ Rob Respected Sir I am seeing the output on Oscilloscope, Tektronix TDS2024C, 200MHz 2GS/s. Thanks & Regards... :-)
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #42 on: October 02, 2012, 10:27:41 pm » |
but it is not giving 16 clock cycle. How do you know that? ______ Rob Respected Sir I am seeing the output on Oscilloscope, Tektronix TDS2024C, 200MHz 2GS/s. Thanks & Regards... :-) Respected Sir With the following code Arduino board is not able to generate its own clock it takes another boards when connected with MISO, MOSI, CS and SCK. I found that once SPI_SlaveReceive(); function is initialized it is not able to generate the clock, if I comment this function or send the data or use SPI.transfer(); before SPI_SlaveReceive(); then it is able to generate the clock. What would be the reason and how to overcome this problem. #include <SPI.h>
#define SCK_PIN 13 #define MISO_PIN 12 #define MOSI_PIN 11 #define SS_PIN 10
unsigned char data; int array[10] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }, ii;
void SlaveInit(void) { // Set MISO output, all others input pinMode(SCK_PIN, INPUT); pinMode(MOSI_PIN, INPUT); pinMode(MISO_PIN, OUTPUT); pinMode(SS_PIN, INPUT);
// Enable SPI SPCR = B00101100; SPCR = (1<<SPE); }
void setup(){ Serial.begin(9600); SPI.begin(); }
void loop() { unsigned char hg = 0; Serial.println("Data Received from Master Board"); SlaveInit(); data = SPI_SlaveReceive(); Serial.println(data, HEX); hg = data; data = 0; delay(1000); if(hg == 0x3D) { Serial.println("Writting Data on SPI bus"); pinMode(SS_PIN, OUTPUT); digitalWrite(SS_PIN, LOW); delay(1000); for(ii=0;ii<10;ii++){ SPI.transfer(array[ii]); Serial.println(array[ii], BIN); delay(1000); } digitalWrite(SS_PIN, HIGH); delay(1000); Serial.println("Sending Done"); delay(1000); }
}
unsigned char SPI_SlaveReceive() { while(!(SPSR & (1<<SPIF))); return SPDR; }
Thanks & Regards.... :-)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #43 on: October 02, 2012, 10:46:15 pm » |
I found that once SPI_SlaveReceive(); function is initialized it is not able to generate the clock ... I don't understand what you are saying here. The master generates the clock, not the slave.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #44 on: October 02, 2012, 10:51:12 pm » |
I found that once SPI_SlaveReceive(); function is initialized it is not able to generate the clock ... I don't understand what you are saying here. The master generates the clock, not the slave. Respected Sir Actually once it receive a data in slave mode then SPI clock becomes dead from this board, I want that my both the board should work as master and both should receive the data and send the data. Can we do like this. Is multimaster concept is same as what I am trying to do. Please guide me Sir. Thanks & Regards.... :-)
|
|
|
|
|
Logged
|
|
|
|
|
|