Changeset 566 for trunk/electronics/avr
- Timestamp:
- 10/15/09 03:01:48 (2 years ago)
- Location:
- trunk/electronics/avr/can-bridge
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/electronics/avr/can-bridge/main.c
r565 r566 42 42 READ_DATA, 43 43 ERROR, 44 VALID, 44 45 END_OF_FRAME, 45 46 SEND_FRAME, … … 68 69 case READ_EID: 69 70 next_state = ERROR; 70 if ((tmp = read_ascii_byte()) == -1) break; 71 msg.sidh = tmp; 72 if ((tmp = read_ascii_byte()) == -1) break; 73 msg.sidl = tmp; 74 if ((tmp = read_ascii_byte()) == -1) break; 75 msg.eid8 = tmp; 76 if ((tmp = read_ascii_byte()) == -1) break; 77 msg.eid0 = tmp; 71 for (int i = 0; i < 4; i++) { 72 if ((tmp = read_ascii_byte()) == -1) goto reerror; 73 msg.addr[i] = tmp; 74 } 78 75 next_state = READ_DLC; 79 break;76 reerror: break; 80 77 case READ_DLC: 81 78 next_state = ERROR; … … 111 108 //can_print(&msg); 112 109 can_send_message(&msg); 110 next_state = VALID; 111 break; 112 case VALID: 113 usart_put('Z'); 114 usart_put('\r'); 113 115 next_state = WAIT_TAG; 114 116 CANMSG_ZERO(&msg); -
trunk/electronics/avr/can-bridge/mcp.c
r564 r566 138 138 { 139 139 uint8_t i; 140 uint8_t tmp; 140 141 _setcs(kCSLow); 141 142 spi_send(kCmdReadRXBuffer | rxbuf); 142 143 143 msg->sidh = spi_recv(); 144 msg->sidl = spi_recv(); 145 msg->sidl &= ~0x18; 146 msg->eid8 = spi_recv(); 147 msg->eid0 = spi_recv(); 144 tmp = spi_recv(); 145 msg->addr[0] = tmp >> 3; 146 msg->addr[1] = ((tmp & 0x07) << 5); 147 tmp = spi_recv(); 148 msg->addr[1] |= ((tmp & 0xE0) >> 3) | (tmp & 0x03); 149 msg->addr[2] = spi_recv(); 150 msg->addr[3] = spi_recv(); 151 152 153 //msg->sidh = spi_recv(); 154 //msg->sidl = spi_recv(); 155 //msg->sidl &= ~0x18; 156 //msg->eid8 = spi_recv(); 157 //msg->eid0 = spi_recv(); 148 158 149 159 msg->dlc = spi_recv() & 0x0F; … … 159 169 uint8_t i; 160 170 usart_put('T'); 161 usart_print_hex(msg->sidh); 162 usart_print_hex(msg->sidl); 163 usart_print_hex(msg->eid8); 164 usart_print_hex(msg->eid0); 171 172 for (i = 0; i < 4; i++) 173 usart_print_hex(msg->addr[i]); 174 175 //usart_print_hex(msg->sidh); 176 //usart_print_hex(msg->sidl); 177 //usart_print_hex(msg->eid8); 178 //usart_print_hex(msg->eid0); 179 165 180 usart_print_hex_nibble(msg->dlc); 166 181 for (i = 0; i < (msg->dlc & 0x0F); i++) … … 178 193 spi_send(kCmdLoadTXBuffer | txbuf); 179 194 180 spi_send(msg->sidh); 181 spi_send(msg->sidl | ((msg->flags & mCANMSG_EX) ? 0x08 : 0x00)); 182 spi_send(msg->eid8); 183 spi_send(msg->eid0); 195 spi_send((msg->addr[0] << 3) | (msg->addr[1] >> 5)); 196 spi_send( ((msg->addr[1] & 0x1C) << 3) | (msg->addr[1] & 0x03) 197 | ((msg->flags & mCANMSG_EX) ? 0x08 : 0x00)); 198 spi_send(msg->addr[2]); 199 spi_send(msg->addr[3]); 200 201 202 //spi_send(msg->sidh); 203 //spi_send(msg->sidl | ((msg->flags & mCANMSG_EX) ? 0x08 : 0x00)); 204 //spi_send(msg->eid8); 205 //spi_send(msg->eid0); 206 184 207 spi_send(msg->dlc); 185 208 -
trunk/electronics/avr/can-bridge/mcp.h
r564 r566 85 85 86 86 typedef struct { 87 uint8_t sidh; 88 uint8_t sidl; 89 uint8_t eid8; 90 uint8_t eid0; 87 uint8_t addr[4]; 91 88 uint8_t dlc; 92 89 uint8_t data[8]; … … 107 104 108 105 #define CANMSG_ZERO(msg) do { \ 109 (msg)->sidh = 0; \110 (msg)->sidl = 0; \111 (msg)->eid8 = 0; \112 (msg)->eid0 = 0; \113 106 (msg)->dlc = 0; \ 114 107 (msg)->data[0] = 0; \ … … 120 113 (msg)->data[6] = 0; \ 121 114 (msg)->data[7] = 0; \ 115 (msg)->addr[0] = 0; \ 116 (msg)->addr[1] = 0; \ 117 (msg)->addr[2] = 0; \ 118 (msg)->addr[3] = 0; \ 122 119 (msg)->flags = 0; \ 123 120 } while (0);

