Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #45 on: October 02, 2012, 11:02:26 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.... :-) Respected Sir It receives the data in slave mode after receiving the data I want to compare the data and want to send another data on SPI bus in master mode. Is it possible. Please guide me on this. #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 == 0x3B) { 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; }
You can see in the image of Oscilloscope while transmitting data from slave after comparing 0x3b , it is sending even 0x3B also with each data. Why it is happening. Can we clear the buffer before transmission of data. Thanks & Regards.... :-)
|
|
|
|
« Last Edit: October 04, 2012, 10:24:02 pm by ranjeetray »
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #46 on: October 08, 2012, 11:46:54 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.... :-) Respected Sir It receives the data in slave mode after receiving the data I want to compare the data and want to send another data on SPI bus in master mode. Is it possible. Please guide me on this. #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 == 0x3B) { 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; }
You can see in the image of Oscilloscope while transmitting data from slave after comparing 0x3b , it is sending even 0x3B also with each data. Why it is happening. Can we clear the buffer before transmission of data. Thanks & Regards.... :-) Hi...!!! Respected Sir, Can we flush the buffer like SPDR, SPSR registers. How can we do this. Thanks & Regards... :-)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14091
Lua rocks!
|
 |
« Reply #47 on: October 09, 2012, 12:02:34 am » |
I don't understand what you are doing here: SlaveInit(); data = SPI_SlaveReceive(); Serial.println(data, HEX); hg = data; data = 0; delay(1000);
if(hg == 0x3B) { 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); }
You are receiving a byte from a SPI master (in slave mode) and then sending it back? Why bother? Plus, you are not changing to master mode. So you won't be sending anything back.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #48 on: October 09, 2012, 01:02:04 am » |
I don't understand what you are doing here: SlaveInit(); data = SPI_SlaveReceive(); Serial.println(data, HEX); hg = data; data = 0; delay(1000);
if(hg == 0x3B) { 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); }
You are receiving a byte from a SPI master (in slave mode) and then sending it back? Why bother? Plus, you are not changing to master mode. So you won't be sending anything back. Respected Sir Thanks a lot for your kind reply. I am reading data on SPI bus and trying to send back data on the same bus to other board from which I have received a byte of data. But I am not able to change the mode, please suggest me how to change mode from slave to master. And I am thinking that once it comes out the slave mode loop it should act as a master by default. Can it happen like this. Thanks & Regards... :-)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14091
Lua rocks!
|
 |
« Reply #49 on: October 09, 2012, 01:11:02 am » |
What other board? How is everything wired up? And I am thinking that once it comes out the slave mode loop it should act as a master by default. Can it happen like this. By default? I don't think so.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #50 on: October 09, 2012, 01:27:44 am » |
What other board? How is everything wired up? And I am thinking that once it comes out the slave mode loop it should act as a master by default. Can it happen like this. By default? I don't think so. Respected Sir Please suggest how to do it and can we clear the buffer also. Please guide me Sir. Because received one byte data is going back on to SPI bus again when I send back data from slave. Thanks & Regards... :-)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14091
Lua rocks!
|
 |
« Reply #51 on: October 09, 2012, 03:19:50 am » |
You've chosen to not answer my question: What other board? How is everything wired up? Why?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14091
Lua rocks!
|
 |
« Reply #52 on: October 09, 2012, 03:20:34 am » |
Because received one byte data is going back on to SPI bus again when I send back data from slave. I don't understand that.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #53 on: October 09, 2012, 04:01:44 am » |
Because received one byte data is going back on to SPI bus again when I send back data from slave. I don't understand that. When I send data from slave to master, data is not available on SPI bus.
|
|
|
|
« Last Edit: October 09, 2012, 04:46:43 am by ranjeetray »
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14091
Lua rocks!
|
 |
« Reply #54 on: October 09, 2012, 04:12:52 pm » |
For the benefit of people who don't have MS Word, your connection diagram is:  Can you explain why you want to send data from one to the other, and then back again? Why not leave it where it started in the first place? And assuming you have a good reason, on my page here: http://www.gammon.com.au/spiI describe how to send data between two Arduinos using SPI. Scroll down to "How to get a response from a slave". I don't understand this sort of talk, to be honest: Because received one byte data is going back on to SPI bus again when I send back data from slave.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14091
Lua rocks!
|
 |
« Reply #55 on: October 09, 2012, 06:08:29 pm » |
What has your diagram above got to do with "SPI interface with other board_AVR_ESK1100"?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 108
|
 |
« Reply #56 on: October 09, 2012, 10:37:57 pm » |
What has your diagram above got to do with "SPI interface with other board_AVR_ESK1100"?
Respected sir Thanks a lot for your kind reply. Actually we are going test IMU(Inertial Measurement Unit) of a satellite, so before testing the actual IMU, I want to create a dummy IMU which will be Arduino board or EVK1100(which will act as Master and will send command for data) and other slave board will be Arduino board which will receive command from IMU master board(Arduino or EVK1100) and then send back required data on SPI bus. I am able to receive command from Master(Arduino board) as 0x3E and when I send back data from Slave(Arduino board) this 0x3E is going with each data, I mean on oscilloscope it appears data(0x12 for example) and 0x3E together, So I want to remove this 0x3E while sending back data from Slave. Is it possible by clearing any buffer. Please guide me Sir. Thanks & Regards... :-)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14091
Lua rocks!
|
 |
« Reply #57 on: October 09, 2012, 10:57:51 pm » |
Please don't send a 2 Mb image of the data. Just copy and paste the text into a message, inside code blocks.
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 75
Posts: 6969
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #58 on: October 09, 2012, 11:15:17 pm » |
I suspect that your 0x3E is still in the SPDR register although it should be overwritten by SPI.transfer(array[ii]) I would think. So I want to remove this 0x3E while sending back data from Slave.Is it possible by clearing any buffer. If 0x12 is written into the SPDR register that's the value that will go out, I don't know why SPI.transfer() would not do that. Have I got this right... Arduino sends 0x3E to IMU. Line turns around. IMU sends data to Arduino. Does this IMU really expect the SPI line to be turned around? Have you got a data sheet? so before testing the actual IMU, I want to create a dummy IMU which will be Arduino board or EVK1100(which will act as Master and will send command for data) and other slave board will be Arduino board which will receive command from IMU master board(Arduino or EVK1100) BTW, All this talk of IMU/Arduino/EVK1100 is really confusing the issue IMO, can we just say Arduino and IMU and assume that they are both SPI-capable devices. ______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14091
Lua rocks!
|
 |
« Reply #59 on: October 09, 2012, 11:24:15 pm » |
Every transfer sends one byte and receives one. You don't "clear the buffer". Sending something, and getting a response to what was just sent, involves at least two transfers. You can't get a response at the same time you are sending because each bit is transferred at the same time. Perhaps read this: http://www.gammon.com.au/spiI want to create a dummy IMU which will be Arduino board or EVK1100(which will act as Master and will send command for data) and other slave board will be Arduino board which will receive command from IMU master board(Arduino or EVK1100) and then send back required data on SPI bus. I really don't understand what you are doing. Normally SPI is two-way. You don't flip backwards and forwards from slave to master just to get something back. Please read the link above carefully. Then ask specific questions.
|
|
|
|
|
Logged
|
|
|
|
|
|